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

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

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

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

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

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

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

sc_apdu_get_length:
   43|  4.50k|{
   44|  4.50k|	size_t ret = 4;
   45|       |
   46|  4.50k|	switch (apdu->cse) {
   47|      0|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (47:2): [True: 0, False: 4.50k]
  ------------------
   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|  4.50k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|  4.50k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (51:2): [True: 4.50k, False: 0]
  ------------------
   52|  4.50k|		ret++;
   53|  4.50k|		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: 4.50k]
  ------------------
   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: 4.50k]
  ------------------
   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: 4.50k]
  ------------------
   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: 4.50k]
  ------------------
   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: 4.50k]
  ------------------
   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: 4.50k]
  ------------------
   70|      0|		return 0;
   71|  4.50k|	}
   72|  4.50k|	return ret;
   73|  4.50k|}
sc_apdu2bytes:
   85|  2.25k|{
   86|  2.25k|	u8     *p = out;
   87|       |
   88|  2.25k|	size_t len = sc_apdu_get_length(apdu, proto);
   89|       |
   90|  2.25k|	if (out == NULL || outlen < len)
  ------------------
  |  Branch (90:6): [True: 0, False: 2.25k]
  |  Branch (90:21): [True: 0, False: 2.25k]
  ------------------
   91|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|       |	/* CLA, INS, P1 and P2 */
   93|  2.25k|	*p++ = apdu->cla;
   94|  2.25k|	*p++ = apdu->ins;
   95|  2.25k|	*p++ = apdu->p1;
   96|  2.25k|	*p++ = apdu->p2;
   97|       |	/* case depend part */
   98|  2.25k|	switch (apdu->cse) {
  ------------------
  |  Branch (98:10): [True: 2.25k, False: 0]
  ------------------
   99|      0|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (99:2): [True: 0, False: 2.25k]
  ------------------
  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|  2.25k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|  2.25k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (104:2): [True: 2.25k, False: 0]
  ------------------
  105|  2.25k|		*p = (u8)apdu->le;
  106|  2.25k|		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: 2.25k]
  ------------------
  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: 2.25k]
  ------------------
  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: 2.25k]
  ------------------
  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: 2.25k]
  ------------------
  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: 2.25k]
  ------------------
  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|  2.25k|	}
  170|       |
  171|  2.25k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.25k|#define SC_SUCCESS				0
  ------------------
  172|  2.25k|}
sc_apdu_get_octets:
  176|  2.25k|{
  177|  2.25k|	size_t	nlen;
  178|  2.25k|	u8	*nbuf;
  179|       |
  180|  2.25k|	if (apdu == NULL || buf == NULL || len == NULL)
  ------------------
  |  Branch (180:6): [True: 0, False: 2.25k]
  |  Branch (180:22): [True: 0, False: 2.25k]
  |  Branch (180:37): [True: 0, False: 2.25k]
  ------------------
  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|  2.25k|	nlen = sc_apdu_get_length(apdu, proto);
  185|  2.25k|	if (nlen == 0)
  ------------------
  |  Branch (185:6): [True: 0, False: 2.25k]
  ------------------
  186|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  187|  2.25k|	nbuf = malloc(nlen);
  188|  2.25k|	if (nbuf == NULL)
  ------------------
  |  Branch (188:6): [True: 0, False: 2.25k]
  ------------------
  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|  2.25k|	if (sc_apdu2bytes(ctx, apdu, proto, nbuf, nlen) != SC_SUCCESS) {
  ------------------
  |  |   28|  2.25k|#define SC_SUCCESS				0
  ------------------
  |  Branch (191:6): [True: 0, False: 2.25k]
  ------------------
  192|      0|		free(nbuf);
  193|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  194|      0|	}
  195|  2.25k|	*buf = nbuf;
  196|  2.25k|	*len = nlen;
  197|       |
  198|  2.25k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.25k|#define SC_SUCCESS				0
  ------------------
  199|  2.25k|}
sc_check_apdu:
  257|   646k|{
  258|   646k|	if ((apdu->cse & ~SC_APDU_SHORT_MASK) == 0) {
  ------------------
  |  |  295|   646k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  |  Branch (258:6): [True: 643k, False: 3.17k]
  ------------------
  259|       |		/* length check for short APDU */
  260|   643k|		if (apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0))   {
  ------------------
  |  |  306|    525|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (260:7): [True: 87, False: 643k]
  |  Branch (260:26): [True: 525, False: 642k]
  |  Branch (260:44): [True: 46, False: 479]
  ------------------
  261|    133|			sc_log(card->ctx, "failed length check for short APDU");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  262|    133|			goto error;
  263|    133|		}
  264|   643k|	}
  265|  3.17k|	else if ((apdu->cse & SC_APDU_EXT) != 0) {
  ------------------
  |  |  296|  3.17k|#define SC_APDU_EXT			0x10
  ------------------
  |  Branch (265:11): [True: 3.17k, False: 0]
  ------------------
  266|       |		/* check if the card supports extended APDUs */
  267|  3.17k|		if ((card->caps & SC_CARD_CAP_APDU_EXT) == 0) {
  ------------------
  |  |  554|  3.17k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (267:7): [True: 10, False: 3.16k]
  ------------------
  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.16k|		if (apdu->le > 65536 || apdu->lc > 65535)   {
  ------------------
  |  Branch (272:7): [True: 0, False: 3.16k]
  |  Branch (272:27): [True: 1, False: 3.16k]
  ------------------
  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.16k|	}
  277|      0|	else   {
  278|      0|		goto error;
  279|      0|	}
  280|       |
  281|   646k|	switch (apdu->cse & SC_APDU_SHORT_MASK) {
  ------------------
  |  |  295|   646k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
  282|  9.34k|	case SC_APDU_CASE_1:
  ------------------
  |  |  291|  9.34k|#define SC_APDU_CASE_1			0x01
  ------------------
  |  Branch (282:2): [True: 9.34k, False: 636k]
  ------------------
  283|       |		/* no data is sent or received */
  284|  9.34k|		if (apdu->datalen != 0 || apdu->lc != 0 || apdu->le != 0)
  ------------------
  |  Branch (284:7): [True: 0, False: 9.34k]
  |  Branch (284:29): [True: 0, False: 9.34k]
  |  Branch (284:46): [True: 0, False: 9.34k]
  ------------------
  285|      0|			goto error;
  286|  9.34k|		break;
  287|   188k|	case SC_APDU_CASE_2_SHORT:
  ------------------
  |  |  292|   188k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (287:2): [True: 188k, False: 457k]
  ------------------
  288|       |		/* no data is sent */
  289|   188k|		if (apdu->datalen != 0 || apdu->lc != 0)
  ------------------
  |  Branch (289:7): [True: 0, False: 188k]
  |  Branch (289:29): [True: 0, False: 188k]
  ------------------
  290|      0|			goto error;
  291|       |		/* data is expected       */
  292|   188k|		if (apdu->resplen == 0 || apdu->resp == NULL)
  ------------------
  |  Branch (292:7): [True: 1, False: 188k]
  |  Branch (292:29): [True: 0, False: 188k]
  ------------------
  293|      1|			goto error;
  294|   188k|		break;
  295|   188k|	case SC_APDU_CASE_3_SHORT:
  ------------------
  |  |  293|  82.4k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (295:2): [True: 82.4k, False: 563k]
  ------------------
  296|       |		/* data is sent */
  297|  82.4k|		if (apdu->datalen == 0 || apdu->data == NULL || apdu->lc == 0)
  ------------------
  |  Branch (297:7): [True: 0, False: 82.4k]
  |  Branch (297:29): [True: 0, False: 82.4k]
  |  Branch (297:51): [True: 0, False: 82.4k]
  ------------------
  298|      0|			goto error;
  299|       |		/* no data is expected    */
  300|  82.4k|		if (apdu->le != 0)
  ------------------
  |  Branch (300:7): [True: 0, False: 82.4k]
  ------------------
  301|      0|			goto error;
  302|       |		/* inconsistent datalen   */
  303|  82.4k|		if (apdu->datalen != apdu->lc)
  ------------------
  |  Branch (303:7): [True: 0, False: 82.4k]
  ------------------
  304|      0|			goto error;
  305|  82.4k|		break;
  306|   365k|	case SC_APDU_CASE_4_SHORT:
  ------------------
  |  |  294|   365k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (306:2): [True: 365k, False: 280k]
  ------------------
  307|       |		/* data is sent */
  308|   365k|		if (apdu->datalen == 0 || apdu->data == NULL || apdu->lc == 0)
  ------------------
  |  Branch (308:7): [True: 619, False: 364k]
  |  Branch (308:29): [True: 0, False: 364k]
  |  Branch (308:51): [True: 0, False: 364k]
  ------------------
  309|    619|			goto error;
  310|       |		/* data is expected       */
  311|   364k|		if (apdu->resplen == 0 || apdu->resp == NULL)
  ------------------
  |  Branch (311:7): [True: 0, False: 364k]
  |  Branch (311:29): [True: 0, False: 364k]
  ------------------
  312|      0|			goto error;
  313|       |		/* inconsistent datalen   */
  314|   364k|		if (apdu->datalen != apdu->lc)
  ------------------
  |  Branch (314:7): [True: 0, False: 364k]
  ------------------
  315|      0|			goto error;
  316|   364k|		break;
  317|   364k|	default:
  ------------------
  |  Branch (317:2): [True: 0, False: 646k]
  ------------------
  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|   646k|	}
  321|   645k|	return SC_SUCCESS;
  ------------------
  |  |   28|   645k|#define SC_SUCCESS				0
  ------------------
  322|    764|error:
  323|    764|	sc_log(card->ctx, "Invalid Case %d %s APDU:\n"
  ------------------
  |  |   71|    764|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  326|  1.52k|		apdu->cse & SC_APDU_SHORT_MASK,
  |  |  |  |  ------------------
  |  |  |  |  |  |  295|    764|#define SC_APDU_SHORT_MASK		0x0f
  |  |  |  |  ------------------
  |  |  |  |  327|  1.52k|		(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  296|    764|#define SC_APDU_EXT			0x10
  |  |  |  |  ------------------
  |  |  |  |  328|  1.52k|		apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
  |  |  |  |  329|  1.52k|		(unsigned long) apdu->lc, (unsigned long) apdu->le,
  |  |  |  |  330|  1.52k|		apdu->resp, (unsigned long) apdu->resplen,
  |  |  |  |  331|  1.52k|		apdu->data, (unsigned long) apdu->datalen, apdu->flags);
  |  |  ------------------
  ------------------
  324|    764|		"cse=%02x cla=%02x ins=%02x p1=%02x p2=%02x lc=%lu le=%lu\n"
  325|    764|		"resp=%p resplen=%lu data=%p datalen=%lu flags=0x%8.8lx",
  326|    764|		apdu->cse & SC_APDU_SHORT_MASK,
  327|    764|		(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  328|    764|		apdu->cse, apdu->cla, apdu->ins, apdu->p1, apdu->p2,
  329|    764|		(unsigned long) apdu->lc, (unsigned long) apdu->le,
  330|    764|		apdu->resp, (unsigned long) apdu->resplen,
  331|    764|		apdu->data, (unsigned long) apdu->datalen, apdu->flags);
  332|    764|	return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    764|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  333|   646k|}
sc_transmit_apdu:
  544|   623k|{
  545|   623k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   623k|#define SC_SUCCESS				0
  ------------------
  546|       |
  547|   623k|	if (card == NULL || apdu == NULL)
  ------------------
  |  Branch (547:6): [True: 0, False: 623k]
  |  Branch (547:22): [True: 0, False: 623k]
  ------------------
  548|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  549|       |
  550|   623k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   623k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   623k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   623k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   623k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 623k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  551|       |
  552|       |	/* determine the APDU type if necessary, i.e. to use
  553|       |	 * short or extended APDUs  */
  554|   623k|	sc_detect_apdu_cse(card, apdu);
  555|       |	/* basic APDU consistency check */
  556|   623k|	r = sc_check_apdu(card, apdu);
  557|   623k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   623k|#define SC_SUCCESS				0
  ------------------
  |  Branch (557:6): [True: 759, False: 622k]
  ------------------
  558|    759|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    759|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  559|       |
  560|   622k|	r = sc_lock(card);	/* acquire card lock*/
  561|   622k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|   622k|#define SC_SUCCESS				0
  ------------------
  |  Branch (561:6): [True: 0, False: 622k]
  ------------------
  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|   622k|#if ENABLE_SM
  567|   622k|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|  1.24M|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (567:6): [True: 3.67k, False: 619k]
  ------------------
  568|  3.67k|			&& (apdu->flags & SC_APDU_FLAGS_CHAINING) != 0
  ------------------
  |  |  306|  3.67k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (568:7): [True: 0, False: 3.67k]
  ------------------
  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|   622k|#endif
  574|   622k|	if ((apdu->flags & SC_APDU_FLAGS_CHAINING) != 0) {
  ------------------
  |  |  306|   622k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (574:6): [True: 19.8k, False: 602k]
  ------------------
  575|       |		/* divide et impera: transmit APDU in chunks with Lc <= max_send_size
  576|       |		 * bytes using command chaining */
  577|  19.8k|		size_t    len  = apdu->datalen;
  578|  19.8k|		const u8  *buf = apdu->data;
  579|  19.8k|		size_t    max_send_size = sc_get_max_send_size(card);
  580|       |
  581|  39.8k|		while (len != 0) {
  ------------------
  |  Branch (581:10): [True: 20.9k, False: 18.9k]
  ------------------
  582|  20.9k|			size_t    plen;
  583|  20.9k|			sc_apdu_t tapdu;
  584|  20.9k|			int       last = 0;
  585|       |
  586|  20.9k|			tapdu = *apdu;
  587|       |			/* clear chaining flag */
  588|  20.9k|			tapdu.flags &= ~SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  20.9k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  589|  20.9k|			if (len > max_send_size) {
  ------------------
  |  Branch (589:8): [True: 1.62k, False: 19.2k]
  ------------------
  590|       |				/* adjust APDU case: in case of CASE 4 APDU
  591|       |				 * the intermediate APDU are of CASE 3 */
  592|  1.62k|				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
  ------------------
  |  |  295|  1.62k|#define SC_APDU_SHORT_MASK		0x0f
  ------------------
              				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
  ------------------
  |  |  294|  1.62k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (592:9): [True: 1.62k, False: 0]
  ------------------
  593|  1.62k|					tapdu.cse--;
  594|       |				/* XXX: the chunk size must be adjusted when
  595|       |				 *      secure messaging is used */
  596|  1.62k|				plen          = max_send_size;
  597|  1.62k|				tapdu.cla    |= 0x10;
  598|       |				/* the intermediate APDU don't expect response data */
  599|  1.62k|				tapdu.le      = 0;
  600|  1.62k|				tapdu.resplen = 0;
  601|  1.62k|				tapdu.resp    = NULL;
  602|  19.2k|			} else {
  603|  19.2k|				plen = len;
  604|  19.2k|				last = 1;
  605|  19.2k|			}
  606|  20.9k|			tapdu.data    = buf;
  607|  20.9k|			tapdu.datalen = tapdu.lc = plen;
  608|       |
  609|  20.9k|			r = sc_check_apdu(card, &tapdu);
  610|  20.9k|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  20.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (610:8): [True: 5, False: 20.9k]
  ------------------
  611|      5|				sc_log(card->ctx, "inconsistent APDU while chaining");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  612|      5|				break;
  613|      5|			}
  614|       |
  615|  20.9k|			r = sc_transmit(card, &tapdu);
  616|  20.9k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  20.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (616:8): [True: 340, False: 20.5k]
  ------------------
  617|    340|				break;
  618|  20.5k|			if (last != 0) {
  ------------------
  |  Branch (618:8): [True: 18.9k, False: 1.62k]
  ------------------
  619|       |				/* in case of the last APDU set the SW1
  620|       |				 * and SW2 bytes in the original APDU */
  621|  18.9k|				apdu->sw1 = tapdu.sw1;
  622|  18.9k|				apdu->sw2 = tapdu.sw2;
  623|  18.9k|				apdu->resplen = tapdu.resplen;
  624|  18.9k|			} else {
  625|       |				/* otherwise check the status bytes */
  626|  1.62k|				r = sc_check_sw(card, tapdu.sw1, tapdu.sw2);
  627|  1.62k|				if (r != SC_SUCCESS)
  ------------------
  |  |   28|  1.62k|#define SC_SUCCESS				0
  ------------------
  |  Branch (627:9): [True: 501, False: 1.12k]
  ------------------
  628|    501|					break;
  629|  1.62k|			}
  630|  20.0k|			len -= plen;
  631|  20.0k|			buf += plen;
  632|  20.0k|		}
  633|   602k|	} else {
  634|       |		/* transmit single APDU */
  635|   602k|		r = sc_transmit(card, apdu);
  636|   602k|	}
  637|       |
  638|   622k|	if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|  1.24M|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              	if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   622k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (638:6): [True: 0, False: 622k]
  |  Branch (638:34): [True: 0, False: 622k]
  ------------------
  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|   622k|	if (sc_unlock(card) != SC_SUCCESS)
  ------------------
  |  |   28|   622k|#define SC_SUCCESS				0
  ------------------
  |  Branch (645:6): [True: 0, False: 622k]
  ------------------
  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|   622k|	return r;
  649|   622k|}
sc_bytes2apdu:
  654|     70|{
  655|     70|	const unsigned char *p;
  656|     70|	size_t len0;
  657|       |
  658|     70|	if (!buf || !apdu)
  ------------------
  |  Branch (658:6): [True: 0, False: 70]
  |  Branch (658:14): [True: 0, False: 70]
  ------------------
  659|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  660|       |
  661|     70|	len0 = len;
  662|     70|	if (len < 4) {
  ------------------
  |  Branch (662:6): [True: 0, False: 70]
  ------------------
  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|     70|	memset(apdu, 0, sizeof *apdu);
  668|     70|	p = buf;
  669|     70|	apdu->cla = *p++;
  670|     70|	apdu->ins = *p++;
  671|     70|	apdu->p1 = *p++;
  672|     70|	apdu->p2 = *p++;
  673|     70|	len -= 4;
  674|       |
  675|     70|	if (!len) {
  ------------------
  |  Branch (675:6): [True: 0, False: 70]
  ------------------
  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|     70|	if (*p == 0 && len >= 3) {
  ------------------
  |  Branch (683:6): [True: 0, False: 70]
  |  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|     70|	else {
  728|       |		/* ...must be a short APDU */
  729|     70|		if (len == 1) {
  ------------------
  |  Branch (729:7): [True: 70, False: 0]
  ------------------
  730|     70|			apdu->le = *p++;
  731|     70|			if (apdu->le == 0)
  ------------------
  |  Branch (731:8): [True: 0, False: 70]
  ------------------
  732|      0|				apdu->le = 0xff+1;
  733|     70|			len--;
  734|     70|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|     70|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  735|     70|		}
  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|     70|	}
  761|     70|	if (len) {
  ------------------
  |  Branch (761:6): [True: 0, False: 70]
  ------------------
  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|     70|	sc_log(ctx,
  ------------------
  |  |   71|     70|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  768|    140|	       apdu->cse & SC_APDU_SHORT_MASK,
  |  |  |  |  ------------------
  |  |  |  |  |  |  295|     70|#define SC_APDU_SHORT_MASK		0x0f
  |  |  |  |  ------------------
  |  |  |  |  769|    140|	       (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  |  |  |  |  ------------------
  |  |  |  |  |  |  296|     70|#define SC_APDU_EXT			0x10
  |  |  |  |  ------------------
  |  |  |  |  770|    140|	       len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc,
  |  |  |  |  771|    140|	       apdu->le);
  |  |  ------------------
  ------------------
  767|     70|	       "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|     70|	       apdu->cse & SC_APDU_SHORT_MASK,
  769|     70|	       (apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
  770|     70|	       len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc,
  771|     70|	       apdu->le);
  772|       |
  773|     70|	return SC_SUCCESS;
  ------------------
  |  |   28|     70|#define SC_SUCCESS				0
  ------------------
  774|     70|}
apdu.c:sc_detect_apdu_cse:
  341|   623k|{
  342|   623k|	if (apdu->cse == SC_APDU_CASE_2 || apdu->cse == SC_APDU_CASE_3 ||
  ------------------
  |  |  301|  1.24M|#define SC_APDU_CASE_2			0x22
  ------------------
              	if (apdu->cse == SC_APDU_CASE_2 || apdu->cse == SC_APDU_CASE_3 ||
  ------------------
  |  |  302|  1.10M|#define SC_APDU_CASE_3			0x23
  ------------------
  |  Branch (342:6): [True: 140k, False: 483k]
  |  Branch (342:37): [True: 25, False: 483k]
  ------------------
  343|   483k|	    apdu->cse == SC_APDU_CASE_4) {
  ------------------
  |  |  303|   483k|#define SC_APDU_CASE_4			0x24
  ------------------
  |  Branch (343:6): [True: 17.9k, False: 465k]
  ------------------
  344|   158k|		int btype = apdu->cse & SC_APDU_SHORT_MASK;
  ------------------
  |  |  295|   158k|#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|   158k|		if ((apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0)) &&
  ------------------
  |  |  306|    274|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  |  Branch (349:8): [True: 1.28k, False: 157k]
  |  Branch (349:27): [True: 274, False: 156k]
  |  Branch (349:45): [True: 19, False: 255]
  ------------------
  350|  1.29k|		    (card->caps & SC_CARD_CAP_APDU_EXT) != 0)
  ------------------
  |  |  554|  1.29k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (350:7): [True: 1.19k, False: 106]
  ------------------
  351|  1.19k|			btype |= SC_APDU_EXT;
  ------------------
  |  |  296|  1.19k|#define SC_APDU_EXT			0x10
  ------------------
  352|   158k|		apdu->cse = btype;
  353|   158k|	}
  354|   623k|}
apdu.c:sc_transmit:
  510|   623k|{
  511|   623k|	struct sc_context *ctx  = card->ctx;
  512|   623k|	size_t       olen  = apdu->resplen;
  513|   623k|	int          r;
  514|       |
  515|   623k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   623k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   623k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   623k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   623k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 623k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|       |
  517|   623k|	r = sc_single_transmit(card, apdu);
  518|   623k|	LOG_TEST_RET(ctx, r, "transmit APDU failed");
  ------------------
  |  |  174|   623k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   623k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   623k|	int _ret = (r); \
  |  |  |  |  168|   623k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 569, False: 623k]
  |  |  |  |  ------------------
  |  |  |  |  169|    569|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    569|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    569|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    569|		return _ret; \
  |  |  |  |  172|    569|	} \
  |  |  |  |  173|   623k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 623k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|   623k|	if (apdu->sw1 == 0x6C && (apdu->flags & SC_APDU_FLAGS_NO_RETRY_WL) == 0) {
  ------------------
  |  |  312|  3.67k|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  |  Branch (524:6): [True: 3.67k, False: 619k]
  |  Branch (524:27): [True: 3.28k, False: 387]
  ------------------
  525|  3.28k|		r = sc_set_le_and_transmit(card, apdu, olen);
  526|  3.28k|		LOG_TEST_RET(ctx, r, "cannot re-transmit APDU ");
  ------------------
  |  |  174|  3.28k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.28k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.28k|	int _ret = (r); \
  |  |  |  |  168|  3.28k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.26k, False: 2.02k]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.26k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.26k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.26k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.26k|		return _ret; \
  |  |  |  |  172|  1.26k|	} \
  |  |  |  |  173|  3.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.02k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  527|  3.28k|	}
  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|   622k|	if (apdu->sw1 == 0x61 && (apdu->flags & SC_APDU_FLAGS_NO_GET_RESP) == 0) {
  ------------------
  |  |  308|  56.6k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  |  Branch (534:6): [True: 56.6k, False: 565k]
  |  Branch (534:27): [True: 45.1k, False: 11.4k]
  ------------------
  535|  45.1k|		r = sc_get_response(card, apdu, olen);
  536|  45.1k|		LOG_TEST_RET(ctx, r, "cannot get all data with 'GET RESPONSE'");
  ------------------
  |  |  174|  45.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  45.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  45.1k|	int _ret = (r); \
  |  |  |  |  168|  45.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8.01k, False: 37.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|  8.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|  8.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  8.01k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  8.01k|		return _ret; \
  |  |  |  |  172|  8.01k|	} \
  |  |  |  |  173|  45.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 37.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  537|  45.1k|	}
  538|       |
  539|   614k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|   614k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   614k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   614k|	int _ret = r; \
  |  |  |  |  155|   614k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 614k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   614k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 614k]
  |  |  |  |  ------------------
  |  |  |  |  157|   614k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   614k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   614k|	return _ret; \
  |  |  |  |  163|   614k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  540|   614k|}
apdu.c:sc_single_transmit:
  359|   625k|{
  360|   625k|	struct sc_context *ctx  = card->ctx;
  361|   625k|	int rv;
  362|       |
  363|   625k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   625k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   625k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   625k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   625k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 625k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  364|   625k|	if (card->reader->ops->transmit == NULL)
  ------------------
  |  Branch (364:6): [True: 0, False: 625k]
  ------------------
  365|   625k|		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|   625k|	sc_log(ctx,
  ------------------
  |  |   71|   625k|#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|   625k|	       "CLA:%X, INS:%X, P1:%X, P2:%X, data(%"SC_FORMAT_LEN_SIZE_T"u) %p",
  369|   625k|	       apdu->cla, apdu->ins, apdu->p1, apdu->p2, apdu->datalen,
  370|   625k|	       apdu->data);
  371|   625k|#ifdef ENABLE_SM
  372|   625k|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|  1.25M|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (372:6): [True: 3.69k, False: 622k]
  ------------------
  373|  3.69k|		   	&& (apdu->flags & SC_APDU_FLAGS_NO_SM) == 0) {
  ------------------
  |  |  314|  3.69k|#define SC_APDU_FLAGS_NO_SM		0x00000008UL
  ------------------
  |  Branch (373:10): [True: 1.84k, False: 1.84k]
  ------------------
  374|  1.84k|		LOG_FUNC_RETURN(ctx, sc_sm_single_transmit(card, apdu));
  ------------------
  |  |  164|  1.84k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.84k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.84k|	int _ret = r; \
  |  |  |  |  155|  1.84k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.84k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.84k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    571|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 571, False: 1.27k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.84k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.84k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.84k|	return _ret; \
  |  |  |  |  163|  1.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  375|  1.84k|	}
  376|   624k|#endif
  377|       |
  378|       |	/* send APDU to the reader driver */
  379|   624k|	rv = card->reader->ops->transmit(card->reader, apdu);
  380|   624k|	LOG_TEST_RET(ctx, rv, "unable to transmit APDU");
  ------------------
  |  |  174|   624k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   624k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   624k|	int _ret = (r); \
  |  |  |  |  168|   624k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 624k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|   624k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 624k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|       |
  382|   624k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|   624k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   624k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   624k|	int _ret = r; \
  |  |  |  |  155|   624k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 624k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   624k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 624k]
  |  |  |  |  ------------------
  |  |  |  |  157|   624k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   624k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   624k|	return _ret; \
  |  |  |  |  163|   624k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  383|   624k|}
apdu.c:sc_set_le_and_transmit:
  388|  3.28k|{
  389|  3.28k|	struct sc_context *ctx  = card->ctx;
  390|  3.28k|	size_t nlen = apdu->sw2 ? (size_t)apdu->sw2 : 256;
  ------------------
  |  Branch (390:16): [True: 2.39k, False: 897]
  ------------------
  391|  3.28k|	int rv;
  392|       |
  393|  3.28k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.28k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.28k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.28k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.28k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.28k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|       |	/* we cannot re-transmit the APDU with the demanded Le value
  395|       |	 * as the buffer is too small => error */
  396|  3.28k|	if (olen < nlen)
  ------------------
  |  Branch (396:6): [True: 1.25k, False: 2.03k]
  ------------------
  397|  3.28k|		LOG_TEST_RET(ctx, SC_ERROR_WRONG_LENGTH, "wrong length: required length exceeds resplen");
  ------------------
  |  |  174|  1.25k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.25k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.25k|	int _ret = (r); \
  |  |  |  |  168|  1.25k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.25k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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.25k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|       |
  399|       |	/* don't try again if it doesn't work this time */
  400|  2.03k|	apdu->flags  |= SC_APDU_FLAGS_NO_RETRY_WL;
  ------------------
  |  |  312|  2.03k|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  401|       |	/* set the new expected length */
  402|  2.03k|	apdu->resplen = olen;
  403|  2.03k|	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.03k|	rv = sc_single_transmit(card, apdu);
  414|  2.03k|	LOG_TEST_RET(ctx, rv, "cannot re-transmit APDU");
  ------------------
  |  |  174|  2.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.03k|	int _ret = (r); \
  |  |  |  |  168|  2.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 2.02k]
  |  |  |  |  ------------------
  |  |  |  |  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.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.02k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  415|       |
  416|  2.02k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  2.02k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.02k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.02k|	int _ret = r; \
  |  |  |  |  155|  2.02k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.02k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.02k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.02k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.02k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.02k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.02k|	return _ret; \
  |  |  |  |  163|  2.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  417|  2.02k|}
apdu.c:sc_get_response:
  422|  45.1k|{
  423|  45.1k|	struct sc_context *ctx  = card->ctx;
  424|  45.1k|	size_t le, minlen, buflen;
  425|  45.1k|	unsigned char *buf;
  426|  45.1k|	int rv;
  427|       |
  428|  45.1k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  45.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  45.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  45.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  45.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 45.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|  45.1k|	if (apdu->le == 0) {
  ------------------
  |  Branch (429:6): [True: 10.9k, False: 34.2k]
  ------------------
  430|       |		/* no data is requested => change return value to 0x9000 and ignore the remaining data */
  431|  10.9k|		apdu->sw1 = 0x90;
  432|  10.9k|		apdu->sw2 = 0x00;
  433|  10.9k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.9k|#define SC_SUCCESS				0
  ------------------
  434|  10.9k|	}
  435|       |
  436|       |	/* this should _never_ happen */
  437|  34.2k|	if (!card->ops->get_response)
  ------------------
  |  Branch (437:6): [True: 58, False: 34.1k]
  ------------------
  438|  34.2k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "no GET RESPONSE command");
  ------------------
  |  |  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: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     58|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     58|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     58|		return _ret; \
  |  |  |  |  172|     58|	} \
  |  |  |  |  173|     58|} 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|  34.1k|	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|  34.1k|	buflen = olen - apdu->resplen;
  448|       |
  449|       |	/* 0x6100 means at least 256 more bytes to read */
  450|  34.1k|	le = apdu->sw2 != 0 ? (size_t)apdu->sw2 : 256;
  ------------------
  |  Branch (450:7): [True: 29.0k, False: 5.17k]
  ------------------
  451|       |	/* we try to read at least as much as bytes as promised in the response bytes */
  452|  34.1k|	minlen = le;
  453|       |
  454|  44.0k|	do {
  455|  44.0k|		unsigned char resp[256];
  456|  44.0k|		size_t resp_len = le;
  457|       |
  458|       |		/* we have all the data the caller requested even if the card has more data */
  459|  44.0k|		if (buflen == 0)
  ------------------
  |  Branch (459:7): [True: 5.82k, False: 38.2k]
  ------------------
  460|  5.82k|			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|  38.2k|		memset(resp, 0, sizeof(resp));
  465|  38.2k|		rv = card->ops->get_response(card, &resp_len, resp);
  466|  38.2k|		if (rv < 0)   {
  ------------------
  |  Branch (466:7): [True: 7.95k, False: 30.2k]
  ------------------
  467|  7.95k|#ifdef ENABLE_SM
  468|  7.95k|			if (resp_len)   {
  ------------------
  |  Branch (468:8): [True: 4.26k, False: 3.69k]
  ------------------
  469|  4.26k|				sc_log_hex(ctx, "SM response data", resp, resp_len);
  ------------------
  |  |  129|  4.26k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  4.26k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  470|  4.26k|				sc_sm_update_apdu_response(card, resp, resp_len, rv, apdu);
  471|  4.26k|			}
  472|  7.95k|#endif
  473|  7.95k|			LOG_TEST_RET(ctx, rv, "GET RESPONSE error");
  ------------------
  |  |  174|  7.95k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.95k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.95k|	int _ret = (r); \
  |  |  |  |  168|  7.95k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7.95k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|  7.95k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  474|  7.95k|		}
  475|       |
  476|  30.2k|		le = resp_len;
  477|       |		/* copy as much as will fit in requested buffer */
  478|  30.2k|		if (buflen < le)
  ------------------
  |  Branch (478:7): [True: 1.36k, False: 28.9k]
  ------------------
  479|  1.36k|			le = buflen;
  480|       |
  481|  30.2k|		memcpy(buf, resp, le);
  482|  30.2k|		buf    += le;
  483|  30.2k|		buflen -= le;
  484|       |
  485|  30.2k|		minlen -= le;
  486|  30.2k|		if (rv != 0)
  ------------------
  |  Branch (486:7): [True: 9.86k, False: 20.4k]
  ------------------
  487|  9.86k|			le = minlen = (size_t)rv;
  488|  20.4k|		else
  489|       |			/* if the card has returned 0x9000 but we still expect data ask for more
  490|       |			 * until we have read enough bytes */
  491|  20.4k|			le = minlen;
  492|  30.2k|	} while (rv != 0 && minlen != 0);
  ------------------
  |  Branch (492:11): [True: 9.86k, False: 20.4k]
  |  Branch (492:22): [True: 9.86k, False: 0]
  ------------------
  493|       |
  494|       |	/* we've read all data, let's return 0x9000 */
  495|  26.2k|	apdu->resplen = buf - apdu->resp;
  496|  26.2k|	apdu->sw1 = 0x90;
  497|  26.2k|	apdu->sw2 = 0x00;
  498|       |
  499|  26.2k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  26.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  26.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  26.2k|	int _ret = r; \
  |  |  |  |  155|  26.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  26.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 26.2k]
  |  |  |  |  ------------------
  |  |  |  |  157|  26.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  26.2k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  26.2k|	return _ret; \
  |  |  |  |  163|  26.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  500|  26.2k|}

sc_asn1_read_tag:
   64|   330k|{
   65|   330k|	const u8 *p = *buf;
   66|   330k|	size_t left = buflen, len;
   67|   330k|	unsigned int cla, tag, i;
   68|       |
   69|   330k|	*buf = NULL;
   70|       |
   71|   330k|	if (left == 0 || !p || buflen == 0)
  ------------------
  |  Branch (71:6): [True: 1.81k, False: 328k]
  |  Branch (71:19): [True: 0, False: 328k]
  |  Branch (71:25): [True: 0, False: 328k]
  ------------------
   72|  1.81k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.81k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   73|   328k|	if (*p == 0xff || *p == 0) {
  ------------------
  |  Branch (73:6): [True: 2.22k, False: 326k]
  |  Branch (73:20): [True: 13.8k, False: 312k]
  ------------------
   74|       |		/* end of data reached */
   75|  16.0k|		*taglen = 0;
   76|  16.0k|		*tag_out = SC_ASN1_TAG_EOC;
  ------------------
  |  |  194|  16.0k|#define SC_ASN1_TAG_EOC			0
  ------------------
   77|  16.0k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.0k|#define SC_SUCCESS				0
  ------------------
   78|  16.0k|	}
   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|   312k|	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  184|   312k|#define SC_ASN1_TAG_CLASS		0xC0
  ------------------
              	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  190|   312k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
   85|   312k|	tag = *p & SC_ASN1_TAG_PRIMITIVE;
  ------------------
  |  |  191|   312k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
   86|   312k|	if (left < 1)
  ------------------
  |  Branch (86:6): [True: 0, False: 312k]
  ------------------
   87|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   88|   312k|	p++;
   89|   312k|	left--;
   90|   312k|	if (tag == SC_ASN1_TAG_PRIMITIVE) {
  ------------------
  |  |  191|   312k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  |  Branch (90:6): [True: 3.70k, False: 308k]
  ------------------
   91|       |		/* high tag number */
   92|  3.70k|		size_t n = SC_ASN1_TAGNUM_SIZE - 1;
  ------------------
  |  |  145|  3.70k|#define SC_ASN1_TAGNUM_SIZE		3
  ------------------
   93|       |		/* search the last tag octet */
   94|  5.97k|		do {
   95|  5.97k|			if (left == 0 || n == 0)
  ------------------
  |  Branch (95:8): [True: 183, False: 5.79k]
  |  Branch (95:21): [True: 150, False: 5.64k]
  ------------------
   96|       |				/* either an invalid tag or it doesn't fit in
   97|       |				 * unsigned int */
   98|    333|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    333|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   99|  5.64k|			tag <<= 8;
  100|  5.64k|			tag |= *p;
  101|  5.64k|			p++;
  102|  5.64k|			left--;
  103|  5.64k|			n--;
  104|  5.64k|		} while (tag & 0x80);
  ------------------
  |  Branch (104:12): [True: 2.27k, False: 3.36k]
  ------------------
  105|  3.70k|	}
  106|       |
  107|       |	/* parse length byte(s) */
  108|   312k|	if (left == 0)
  ------------------
  |  Branch (108:6): [True: 2.01k, False: 310k]
  ------------------
  109|  2.01k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  2.01k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  110|   310k|	len = *p;
  111|   310k|	p++;
  112|   310k|	left--;
  113|   310k|	if (len & 0x80) {
  ------------------
  |  Branch (113:6): [True: 53.3k, False: 256k]
  ------------------
  114|  53.3k|		len &= 0x7f;
  115|  53.3k|		unsigned int a = 0;
  116|  53.3k|		if (len > sizeof a || len > left)
  ------------------
  |  Branch (116:7): [True: 13.5k, False: 39.8k]
  |  Branch (116:25): [True: 679, False: 39.1k]
  ------------------
  117|  14.2k|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  14.2k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  118|  69.6k|		for (i = 0; i < len; i++) {
  ------------------
  |  Branch (118:15): [True: 30.5k, False: 39.1k]
  ------------------
  119|  30.5k|			a <<= 8;
  120|  30.5k|			a |= *p;
  121|  30.5k|			p++;
  122|  30.5k|			left--;
  123|  30.5k|		}
  124|  39.1k|		len = a;
  125|  39.1k|	}
  126|       |
  127|   296k|	*cla_out = cla;
  128|   296k|	*tag_out = tag;
  129|   296k|	*taglen = len;
  130|   296k|	*buf = p;
  131|       |
  132|   296k|	if (len > left)
  ------------------
  |  Branch (132:6): [True: 24.3k, False: 271k]
  ------------------
  133|  24.3k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  24.3k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  134|       |
  135|   271k|	return SC_SUCCESS;
  ------------------
  |  |   28|   271k|#define SC_SUCCESS				0
  ------------------
  136|   296k|}
sc_format_asn1_entry:
  140|   295k|{
  141|   295k|	entry->parm = parm;
  142|   295k|	entry->arg  = arg;
  143|   295k|	if (set_present)
  ------------------
  |  Branch (143:6): [True: 45.5k, False: 250k]
  ------------------
  144|  45.5k|		entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  45.5k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  145|   295k|}
sc_copy_asn1_entry:
  149|   104k|{
  150|   404k|	while (src->name != NULL) {
  ------------------
  |  Branch (150:9): [True: 300k, False: 104k]
  ------------------
  151|   300k|		*dest = *src;
  152|   300k|		dest++;
  153|   300k|		src++;
  154|   300k|	}
  155|       |	dest->name = NULL;
  156|   104k|}
sc_asn1_find_tag:
  486|  54.4k|{
  487|  54.4k|	size_t left = buflen, taglen;
  488|  54.4k|	const u8 *p = buf;
  489|       |
  490|  54.4k|	*taglen_in = 0;
  491|   118k|	while (left >= 2) {
  ------------------
  |  Branch (491:9): [True: 108k, False: 9.59k]
  ------------------
  492|   108k|		unsigned int cla = 0, tag, mask = 0xff00;
  493|       |
  494|   108k|		buf = p;
  495|       |		/* read a tag */
  496|   108k|		if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   217k|#define SC_SUCCESS				0
  ------------------
  |  Branch (496:7): [True: 10.4k, False: 98.1k]
  ------------------
  497|  98.1k|				|| p == NULL)
  ------------------
  |  Branch (497:8): [True: 7.67k, False: 90.4k]
  ------------------
  498|  18.1k|			return NULL;
  499|       |
  500|  90.4k|		left -= (p - buf);
  501|       |		/* we need to shift the class byte to the leftmost
  502|       |		 * byte of the tag */
  503|  94.3k|		while ((tag & mask) != 0) {
  ------------------
  |  Branch (503:10): [True: 3.82k, False: 90.4k]
  ------------------
  504|  3.82k|			cla  <<= 8;
  505|  3.82k|			mask <<= 8;
  506|  3.82k|		}
  507|       |		/* compare the read tag with the given tag */
  508|  90.4k|		if ((tag | cla) == tag_in) {
  ------------------
  |  Branch (508:7): [True: 26.7k, False: 63.7k]
  ------------------
  509|       |			/* we have a match => return length and value part */
  510|  26.7k|			if (taglen > left)
  ------------------
  |  Branch (510:8): [True: 0, False: 26.7k]
  ------------------
  511|      0|				return NULL;
  512|  26.7k|			*taglen_in = taglen;
  513|  26.7k|			return p;
  514|  26.7k|		}
  515|       |		/* otherwise continue reading tags */
  516|  63.7k|		left -= taglen;
  517|  63.7k|		p += taglen;
  518|  63.7k|	}
  519|  9.59k|	return NULL;
  520|  54.4k|}
sc_asn1_skip_tag:
  524|   151k|{
  525|   151k|	const u8 *p = *buf;
  526|   151k|	size_t len = *buflen, taglen;
  527|   151k|	unsigned int cla = 0, tag;
  528|       |
  529|   151k|	if (sc_asn1_read_tag((const u8 **) &p, len, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   302k|#define SC_SUCCESS				0
  ------------------
  |  Branch (529:6): [True: 25.4k, False: 125k]
  ------------------
  530|   125k|			|| p == NULL)
  ------------------
  |  Branch (530:7): [True: 6.21k, False: 119k]
  ------------------
  531|  31.7k|		return NULL;
  532|   119k|	switch (cla & 0xC0) {
  ------------------
  |  Branch (532:10): [True: 119k, False: 0]
  ------------------
  533|  73.1k|	case SC_ASN1_TAG_UNIVERSAL:
  ------------------
  |  |  185|  73.1k|#define SC_ASN1_TAG_UNIVERSAL		0x00
  ------------------
  |  Branch (533:2): [True: 73.1k, False: 46.5k]
  ------------------
  534|  73.1k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  136|  73.1k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  137|  73.1k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (534:7): [True: 8.04k, False: 65.1k]
  ------------------
  535|  8.04k|			return NULL;
  536|  65.1k|		break;
  537|  65.1k|	case SC_ASN1_TAG_APPLICATION:
  ------------------
  |  |  186|  7.70k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (537:2): [True: 7.70k, False: 111k]
  ------------------
  538|  7.70k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  136|  7.70k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  138|  7.70k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (538:7): [True: 1.60k, False: 6.10k]
  ------------------
  539|  1.60k|			return NULL;
  540|  6.10k|		break;
  541|  37.3k|	case SC_ASN1_TAG_CONTEXT:
  ------------------
  |  |  187|  37.3k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (541:2): [True: 37.3k, False: 82.3k]
  ------------------
  542|  37.3k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  136|  37.3k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  139|  37.3k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (542:7): [True: 2.64k, False: 34.7k]
  ------------------
  543|  2.64k|			return NULL;
  544|  34.7k|		break;
  545|  34.7k|	case SC_ASN1_TAG_PRIVATE:
  ------------------
  |  |  188|  1.47k|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
  |  Branch (545:2): [True: 1.47k, False: 118k]
  ------------------
  546|  1.47k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  136|  1.47k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  140|  1.47k|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (546:7): [True: 1.47k, False: 0]
  ------------------
  547|  1.47k|			return NULL;
  548|      0|		break;
  549|   119k|	}
  550|   105k|	if (cla & SC_ASN1_TAG_CONSTRUCTED) {
  ------------------
  |  |  190|   105k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (550:6): [True: 68.1k, False: 37.7k]
  ------------------
  551|  68.1k|		if ((tag_in & SC_ASN1_CONS) == 0)
  ------------------
  |  |  141|  68.1k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (551:7): [True: 5.21k, False: 62.9k]
  ------------------
  552|  5.21k|			return NULL;
  553|  68.1k|	} else
  554|  37.7k|		if (tag_in & SC_ASN1_CONS)
  ------------------
  |  |  141|  37.7k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (554:7): [True: 2.03k, False: 35.7k]
  ------------------
  555|  2.03k|			return NULL;
  556|  98.6k|	if ((tag_in & SC_ASN1_TAG_MASK) != tag)
  ------------------
  |  |  144|  98.6k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
  |  Branch (556:6): [True: 26.3k, False: 72.3k]
  ------------------
  557|  26.3k|		return NULL;
  558|  72.3k|	len -= (p - *buf);	/* header size */
  559|  72.3k|	if (taglen > len) {
  ------------------
  |  Branch (559:6): [True: 0, False: 72.3k]
  ------------------
  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|  72.3k|	*buflen -= (p - *buf) + taglen;
  566|  72.3k|	*buf = p + taglen;	/* point to next tag */
  567|  72.3k|	*taglen_out = taglen;
  568|  72.3k|	return p;
  569|  72.3k|}
sc_asn1_verify_tag:
  573|  3.15k|{
  574|  3.15k|	return sc_asn1_skip_tag(ctx, &buf, &buflen, tag_in, taglen_out);
  575|  3.15k|}
sc_asn1_decode_integer:
  734|  3.14k|{
  735|  3.14k|	int    a = 0, is_negative = 0;
  736|  3.14k|	size_t i = 0;
  737|       |
  738|  3.14k|	if (inlen == 0) {
  ------------------
  |  Branch (738:6): [True: 4, False: 3.13k]
  ------------------
  739|      4|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      4|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  740|      4|	}
  741|  3.13k|	if (inlen > sizeof(int)) {
  ------------------
  |  Branch (741:6): [True: 10, False: 3.12k]
  ------------------
  742|     10|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     10|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  743|     10|	}
  744|  3.12k|	if (inbuf[0] & 0x80) {
  ------------------
  |  Branch (744:6): [True: 1.27k, False: 1.85k]
  ------------------
  745|  1.27k|		if (strict && inlen > 1 && inbuf[0] == 0xff && (inbuf[1] & 0x80)) {
  ------------------
  |  Branch (745:7): [True: 0, False: 1.27k]
  |  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.27k|		is_negative = 1;
  749|  1.27k|		a |= 0xff^(*inbuf++);
  750|  1.27k|		i = 1;
  751|  1.85k|	} else {
  752|  1.85k|		if (strict && inlen > 1 && inbuf[0] == 0x00 && (inbuf[1] & 0x80) == 0) {
  ------------------
  |  Branch (752:7): [True: 0, False: 1.85k]
  |  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.85k|	}
  756|  7.19k|	for (; i < inlen; i++) {
  ------------------
  |  Branch (756:9): [True: 4.06k, False: 3.12k]
  ------------------
  757|  4.06k|		if (a > (INT_MAX >> 8) || a < (INT_MIN + (1<<8))) {
  ------------------
  |  Branch (757:7): [True: 0, False: 4.06k]
  |  Branch (757:29): [True: 0, False: 4.06k]
  ------------------
  758|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  759|      0|		}
  760|  4.06k|		a <<= 8;
  761|  4.06k|		if (is_negative) {
  ------------------
  |  Branch (761:7): [True: 1.29k, False: 2.76k]
  ------------------
  762|  1.29k|			a |= 0xff^(*inbuf++);
  763|  2.76k|		} else {
  764|  2.76k|			a |= *inbuf++;
  765|  2.76k|		}
  766|  4.06k|	}
  767|  3.12k|	if (is_negative) {
  ------------------
  |  Branch (767:6): [True: 1.27k, False: 1.85k]
  ------------------
  768|       |		/* Calculate Two's complement from previously positive number */
  769|  1.27k|		a = (-1 * a) - 1;
  770|  1.27k|	}
  771|  3.12k|	*out = a;
  772|  3.12k|	return 0;
  773|  3.12k|}
sc_asn1_decode_object_id:
  834|  10.5k|{
  835|  10.5k|	int large_second_octet = 0;
  836|  10.5k|	unsigned int a = 0;
  837|  10.5k|	const u8 *p = inbuf;
  838|  10.5k|	int *octet;
  839|       |
  840|  10.5k|	if (inlen == 0 || inbuf == NULL || id == NULL)
  ------------------
  |  Branch (840:6): [True: 931, False: 9.61k]
  |  Branch (840:20): [True: 2, False: 9.61k]
  |  Branch (840:37): [True: 0, False: 9.61k]
  ------------------
  841|    933|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    933|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  842|       |
  843|  9.61k|	sc_init_oid(id);
  844|  9.61k|	octet = id->value;
  845|       |
  846|       |	/* The first octet can be 0, 1 or 2 and is derived from the first byte */
  847|  9.61k|	a = MIN(*p / 40, 2);
  ------------------
  |  |   70|  9.61k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 7.07k, False: 2.54k]
  |  |  ------------------
  ------------------
  848|  9.61k|	*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|  9.61k|	if ((*p & 0x80) == 0) {
  ------------------
  |  Branch (853:6): [True: 7.81k, False: 1.79k]
  ------------------
  854|  7.81k|		*octet++ = *p - (a * 40);
  855|  7.81k|		inlen--;
  856|  7.81k|	} else {
  857|  1.79k|		large_second_octet = 1;
  858|  1.79k|	}
  859|       |
  860|  46.1k|	while (inlen) {
  ------------------
  |  Branch (860:9): [True: 38.4k, False: 7.72k]
  ------------------
  861|  38.4k|		if (!large_second_octet)
  ------------------
  |  Branch (861:7): [True: 36.6k, False: 1.79k]
  ------------------
  862|  36.6k|			p++;
  863|       |		/* This signalizes empty most significant bits, which means
  864|       |		 * the unsigned integer encoding is not minimal */
  865|  38.4k|		if (*p == 0x80) {
  ------------------
  |  Branch (865:7): [True: 667, False: 37.7k]
  ------------------
  866|    667|			sc_init_oid(id);
  867|    667|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    667|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  868|    667|		}
  869|       |		/* Use unsigned type here so we can process the whole INT range.
  870|       |		 * Values can not be negative */
  871|  37.7k|		a = *p & 0x7F;
  872|  37.7k|		inlen--;
  873|  57.7k|		while (inlen && *p & 0x80) {
  ------------------
  |  Branch (873:10): [True: 49.5k, False: 8.17k]
  |  Branch (873:19): [True: 20.1k, False: 29.4k]
  ------------------
  874|       |			/* Limit the OID values to int size and do not overflow */
  875|  20.1k|			if (a > (UINT_MAX>>7)) {
  ------------------
  |  Branch (875:8): [True: 115, False: 20.0k]
  ------------------
  876|    115|				sc_init_oid(id);
  877|    115|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    115|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  878|    115|			}
  879|  20.0k|			p++;
  880|  20.0k|			a <<= 7;
  881|  20.0k|			a |= *p & 0x7F;
  882|  20.0k|			inlen--;
  883|  20.0k|		}
  884|  37.6k|		if (*p & 0x80) {
  ------------------
  |  Branch (884:7): [True: 603, False: 37.0k]
  ------------------
  885|       |			/* We dropped out from previous cycle on the end of
  886|       |			 * data while still expecting continuation of value */
  887|    603|			sc_init_oid(id);
  888|    603|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    603|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  889|    603|		}
  890|  37.0k|		if (large_second_octet) {
  ------------------
  |  Branch (890:7): [True: 670, False: 36.3k]
  ------------------
  891|    670|			a -= (2 * 40);
  892|    670|		}
  893|  37.0k|		if (a > INT_MAX) {
  ------------------
  |  Branch (893:7): [True: 366, False: 36.6k]
  ------------------
  894|    366|			sc_init_oid(id);
  895|    366|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    366|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  896|    366|		}
  897|  36.6k|		*octet++ = a;
  898|  36.6k|		if (octet - id->value >= SC_MAX_OBJECT_ID_OCTETS)   {
  ------------------
  |  |   46|  36.6k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (898:7): [True: 136, False: 36.5k]
  ------------------
  899|    136|			sc_init_oid(id);
  900|    136|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    136|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  901|    136|		}
  902|  36.5k|		large_second_octet = 0;
  903|  36.5k|	}
  904|       |
  905|  7.72k|	return 0;
  906|  9.61k|}
sc_asn1_encode_object_id:
  910|  4.50k|{
  911|  4.50k|	u8 temp[SC_MAX_OBJECT_ID_OCTETS*5], *p = temp;
  912|  4.50k|	int	i;
  913|       |
  914|  4.50k|	if (!buflen || !id)
  ------------------
  |  Branch (914:6): [True: 0, False: 4.50k]
  |  Branch (914:17): [True: 0, False: 4.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|  4.50k|	if (id->value[0] == -1 || id->value[1] == -1)
  ------------------
  |  Branch (918:6): [True: 0, False: 4.50k]
  |  Branch (918:28): [True: 0, False: 4.50k]
  ------------------
  919|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  920|       |
  921|  33.2k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++) {
  ------------------
  |  |   46|  33.2k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (921:14): [True: 33.2k, False: 0]
  ------------------
  922|  33.2k|		unsigned int k, shift;
  923|       |
  924|  33.2k|		if (id->value[i] == -1)
  ------------------
  |  Branch (924:7): [True: 4.50k, False: 28.7k]
  ------------------
  925|  4.50k|			break;
  926|       |
  927|  28.7k|		k = id->value[i];
  928|  28.7k|		switch (i) {
  929|  4.50k|		case 0:
  ------------------
  |  Branch (929:3): [True: 4.50k, False: 24.2k]
  ------------------
  930|  4.50k|			if (k > 2)
  ------------------
  |  Branch (930:8): [True: 0, False: 4.50k]
  ------------------
  931|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  932|  4.50k|			*p = k * 40;
  933|  4.50k|			break;
  934|  4.50k|		case 1:
  ------------------
  |  Branch (934:3): [True: 4.50k, False: 24.2k]
  ------------------
  935|  4.50k|			if (k > 39 && id->value[0] < 2) {
  ------------------
  |  Branch (935:8): [True: 0, False: 4.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|  4.50k|			k += *p;
  941|       |			/* fall through */
  942|  24.2k|		default:
  ------------------
  |  Branch (942:3): [True: 19.6k, False: 9.01k]
  ------------------
  943|  24.2k|			shift = 28;
  944|   113k|			while (shift && (k >> shift) == 0)
  ------------------
  |  Branch (944:11): [True: 96.0k, False: 17.0k]
  |  Branch (944:20): [True: 88.9k, False: 7.16k]
  ------------------
  945|  88.9k|				shift -= 7;
  946|  32.1k|			while (shift) {
  ------------------
  |  Branch (946:11): [True: 7.90k, False: 24.2k]
  ------------------
  947|  7.90k|				*p++ = 0x80 | ((k >> shift) & 0x7f);
  948|  7.90k|				shift -= 7;
  949|  7.90k|			}
  950|  24.2k|			*p++ = k & 0x7F;
  951|  24.2k|			break;
  952|  28.7k|		}
  953|  28.7k|	}
  954|       |
  955|  4.50k|	*buflen = p - temp;
  956|       |
  957|  4.50k|	if (buf)   {
  ------------------
  |  Branch (957:6): [True: 4.50k, False: 0]
  ------------------
  958|  4.50k|		*buf = malloc(*buflen);
  959|  4.50k|		if (!*buf)
  ------------------
  |  Branch (959:7): [True: 0, False: 4.50k]
  ------------------
  960|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  961|  4.50k|		memcpy(*buf, temp, *buflen);
  962|  4.50k|	}
  963|  4.50k|	return 0;
  964|  4.50k|}
sc_asn1_put_tag:
  981|  31.1k|{
  982|  31.1k|	size_t c = 0;
  983|  31.1k|	unsigned int tag_len, ii;
  984|  31.1k|	u8 *p = out;
  985|  31.1k|	u8 tag_char[4] = {0, 0, 0, 0};
  986|       |
  987|       |	/* Check tag */
  988|  31.1k|	if (tag == 0 || tag > 0xFFFFFFFF) {
  ------------------
  |  Branch (988:6): [True: 0, False: 31.1k]
  |  Branch (988:18): [True: 0, False: 31.1k]
  ------------------
  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|  62.3k|	for (tag_len = 0; tag; tag >>= 8) {
  ------------------
  |  Branch (992:20): [True: 31.1k, False: 31.1k]
  ------------------
  993|       |		/* Note: tag char will be reversed order. */
  994|  31.1k|		tag_char[tag_len++] = tag & 0xFF;
  995|  31.1k|	}
  996|       |
  997|  31.1k|	if (tag_len > 1)   {
  ------------------
  |  Branch (997:6): [True: 0, False: 31.1k]
  ------------------
  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|  31.1k|	if (datalen > 127) {
  ------------------
  |  Branch (1016:6): [True: 1.23k, False: 29.9k]
  ------------------
 1017|  1.23k|		c = 1;
 1018|  1.90k|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1018:10): [True: 669, False: 1.23k]
  ------------------
 1019|    669|			c++;
 1020|  1.23k|	}
 1021|  31.1k|	if (outlen == 0 || out == NULL) {
  ------------------
  |  Branch (1021:6): [True: 6.31k, False: 24.8k]
  |  Branch (1021:21): [True: 0, False: 24.8k]
  ------------------
 1022|       |		/* Caller only asks for the length that would be written. */
 1023|  6.31k|		return (int)(tag_len + (c + 1) + datalen);
 1024|  6.31k|	}
 1025|       |	/* We will write the tag, so check the length. */
 1026|  24.8k|	if (outlen < tag_len + (c+1) + datalen)
  ------------------
  |  Branch (1026:6): [True: 70, False: 24.7k]
  ------------------
 1027|     70|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     70|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1028|  49.5k|	for (ii=0;ii<tag_len;ii++)
  ------------------
  |  Branch (1028:12): [True: 24.7k, False: 24.7k]
  ------------------
 1029|  24.7k|		*p++ = tag_char[tag_len - ii - 1];
 1030|       |
 1031|  24.7k|	if (c > 0) {
  ------------------
  |  Branch (1031:6): [True: 734, False: 24.0k]
  ------------------
 1032|    734|		*p++ = 0x80 | c;
 1033|  1.82k|		while (c--)
  ------------------
  |  Branch (1033:10): [True: 1.08k, False: 734]
  ------------------
 1034|  1.08k|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1035|    734|	}
 1036|  24.0k|	else {
 1037|  24.0k|		*p++ = datalen & 0x7F;
 1038|  24.0k|	}
 1039|  24.7k|	if(data && datalen > 0) {
  ------------------
  |  Branch (1039:5): [True: 18.6k, False: 6.17k]
  |  Branch (1039:13): [True: 17.2k, False: 1.30k]
  ------------------
 1040|  17.2k|		memcpy(p, data, datalen);
 1041|  17.2k|		p += datalen;
 1042|  17.2k|	}
 1043|  24.7k|	if (ptr != NULL)
  ------------------
  |  Branch (1043:6): [True: 24.7k, False: 0]
  ------------------
 1044|  24.7k|		*ptr = p;
 1045|  24.7k|	return 0;
 1046|  24.8k|}
sc_asn1_decode:
 1816|  26.5k|{
 1817|  26.5k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 0, 0);
 1818|  26.5k|}
sc_asn1_decode_choice:
 1822|  6.57k|{
 1823|  6.57k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 1, 0);
 1824|  6.57k|}
sc_asn1_encode:
 2088|  22.5k|{
 2089|  22.5k|	return asn1_encode(ctx, asn1, ptr, size, 0);
 2090|  22.5k|}
_sc_asn1_encode:
 2094|  4.50k|{
 2095|  4.50k|	return asn1_encode(ctx, asn1, ptr, size, depth);
 2096|  4.50k|}
_sc_asn1_decode:
 2102|  4.55k|{
 2103|  4.55k|	return asn1_decode(ctx, asn1, in, len, newp, left, choice, depth);
 2104|  4.55k|}
sc_der_copy:
 2108|  3.05k|{
 2109|  3.05k|	if (!dst || !src)
  ------------------
  |  Branch (2109:6): [True: 0, False: 3.05k]
  |  Branch (2109:14): [True: 0, False: 3.05k]
  ------------------
 2110|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2111|  3.05k|	memset(dst, 0, sizeof(*dst));
 2112|  3.05k|	if (src->len) {
  ------------------
  |  Branch (2112:6): [True: 3.05k, False: 3]
  ------------------
 2113|  3.05k|		if (!src->value)
  ------------------
  |  Branch (2113:7): [True: 0, False: 3.05k]
  ------------------
 2114|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2115|  3.05k|		dst->value = malloc(src->len);
 2116|  3.05k|		if (!dst->value)
  ------------------
  |  Branch (2116:7): [True: 0, False: 3.05k]
  ------------------
 2117|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2118|  3.05k|		dst->len = src->len;
 2119|  3.05k|		memcpy(dst->value, src->value, src->len);
 2120|  3.05k|	}
 2121|  3.05k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.05k|#define SC_SUCCESS				0
  ------------------
 2122|  3.05k|}
sc_encode_oid:
 2127|  2.87k|{
 2128|  2.87k|	static const struct sc_asn1_entry c_asn1_object_id[2] = {
 2129|  2.87k|		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  159|  2.87k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  200|  2.87k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  2.87k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
 2130|  2.87k|		{ NULL, 0, 0, 0, NULL, NULL }
 2131|  2.87k|	};
 2132|  2.87k|	struct sc_asn1_entry asn1_object_id[2];
 2133|  2.87k|	int rv;
 2134|       |
 2135|  2.87k|	sc_copy_asn1_entry(c_asn1_object_id, asn1_object_id);
 2136|  2.87k|	sc_format_asn1_entry(asn1_object_id + 0, id, NULL, 1);
 2137|       |
 2138|  2.87k|	rv = _sc_asn1_encode(ctx, asn1_object_id, out, size, 1);
 2139|  2.87k|	LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  174|  2.87k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.87k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.87k|	int _ret = (r); \
  |  |  |  |  168|  2.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.87k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  2.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2140|       |
 2141|  2.87k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.87k|#define SC_SUCCESS				0
  ------------------
 2142|  2.87k|}
sc_asn1_decode_ecdsa_signature:
 2243|    192|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|    192|	int i, r;
 2245|    192|	const unsigned char *pseq, *pint, *pend;
 2246|    192|	unsigned int cla, tag;
 2247|    192|	size_t seqlen, intlen;
 2248|       |
 2249|    192|	if (!ctx || !data || !out || !(*out)) {
  ------------------
  |  Branch (2249:6): [True: 0, False: 192]
  |  Branch (2249:14): [True: 0, False: 192]
  |  Branch (2249:23): [True: 0, False: 192]
  |  Branch (2249:31): [True: 0, False: 192]
  ------------------
 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|    192|	if (outlen < 2 * fieldsize) {
  ------------------
  |  Branch (2252:6): [True: 0, False: 192]
  ------------------
 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|    192|	memset(*out, 0, outlen);
 2257|       |
 2258|    192|	pseq = data;
 2259|    192|	r = sc_asn1_read_tag(&pseq, datalen, &cla, &tag, &seqlen);
 2260|    192|	if (pseq == NULL || r < 0 || seqlen == 0 || (cla | tag) != 0x30)
  ------------------
  |  Branch (2260:6): [True: 181, False: 11]
  |  Branch (2260:22): [True: 2, False: 9]
  |  Branch (2260:31): [True: 1, False: 8]
  |  Branch (2260:46): [True: 2, False: 6]
  ------------------
 2261|    192|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Can not find 0x30 tag");
  ------------------
  |  |  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: 186, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    186|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2262|       |
 2263|      6|	pint = pseq;
 2264|      6|	pend = pseq + seqlen;
 2265|      7|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (2265:14): [True: 7, False: 0]
  ------------------
 2266|      7|		r = sc_asn1_read_tag(&pint, (pend - pint), &cla, &tag, &intlen);
 2267|      7|		if (pint == NULL || r < 0 || intlen == 0 || (cla | tag) != 0x02) {
  ------------------
  |  Branch (2267:7): [True: 2, False: 5]
  |  Branch (2267:23): [True: 2, False: 3]
  |  Branch (2267:32): [True: 1, False: 2]
  |  Branch (2267:47): [True: 1, False: 1]
  ------------------
 2268|      6|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      6|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2269|      6|			LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_DATA, "Can not find 0x02");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2270|      6|		}
 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|      6|err:
 2289|      6|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2290|      6|}
asn1.c:decode_bit_string:
  579|  2.86k|{
  580|  2.86k|	const u8 *in = inbuf;
  581|  2.86k|	u8 *out = (u8 *) outbuf;
  582|  2.86k|	int i, count = 0;
  583|  2.86k|	int zero_bits;
  584|  2.86k|	size_t octets_left;
  585|       |
  586|  2.86k|	if (inlen < 1)
  ------------------
  |  Branch (586:6): [True: 3, False: 2.85k]
  ------------------
  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.85k|	if (strict) {
  ------------------
  |  Branch (591:6): [True: 0, False: 2.85k]
  ------------------
  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.85k|	memset(outbuf, 0, outlen);
  602|  2.85k|	zero_bits = *in & 0x07;
  603|  2.85k|	in++;
  604|  2.85k|	octets_left = inlen - 1;
  605|  2.85k|	if (outlen < octets_left)
  ------------------
  |  Branch (605:6): [True: 4, False: 2.85k]
  ------------------
  606|      4|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      4|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  607|       |
  608|   176k|	while (octets_left) {
  ------------------
  |  Branch (608:9): [True: 173k, False: 2.84k]
  ------------------
  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|   173k|		int bits_to_go;
  613|       |
  614|   173k|		*out = 0;
  615|   173k|		if (octets_left == 1 && zero_bits > 0) {
  ------------------
  |  Branch (615:7): [True: 2.78k, False: 170k]
  |  Branch (615:27): [True: 420, False: 2.36k]
  ------------------
  616|    420|			bits_to_go = 8 - zero_bits;
  617|       |			/* Verify the padding is zero bits */
  618|    420|			if (*in & (1 << (zero_bits-1))) {
  ------------------
  |  Branch (618:8): [True: 12, False: 408]
  ------------------
  619|     12|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     12|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  620|     12|			}
  621|    420|		} else
  622|   172k|			bits_to_go = 8;
  623|   173k|		if (invert)
  ------------------
  |  Branch (623:7): [True: 816, False: 172k]
  ------------------
  624|  6.33k|			for (i = 0; i < bits_to_go; i++) {
  ------------------
  |  Branch (624:16): [True: 5.52k, False: 816]
  ------------------
  625|  5.52k|				*out |= ((*in >> (7 - i)) & 1) << i;
  626|  5.52k|			}
  627|   172k|		else {
  628|   172k|			*out = *in;
  629|   172k|		}
  630|   173k|		out++;
  631|   173k|		in++;
  632|   173k|		octets_left--;
  633|   173k|		count++;
  634|   173k|	}
  635|  2.84k|	return (count * 8) - zero_bits;
  636|  2.85k|}
asn1.c:asn1_write_element:
 1056|  32.6k|{
 1057|  32.6k|	unsigned char t;
 1058|  32.6k|	unsigned char *buf, *p;
 1059|  32.6k|	int c = 0;
 1060|  32.6k|	unsigned short_tag;
 1061|  32.6k|	unsigned char tag_char[3] = {0, 0, 0};
 1062|  32.6k|	size_t tag_len, ii;
 1063|       |
 1064|  32.6k|	short_tag = tag & SC_ASN1_TAG_MASK;
  ------------------
  |  |  144|  32.6k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
 1065|  65.3k|	for (tag_len = 0; short_tag >> (8 * tag_len); tag_len++)
  ------------------
  |  Branch (1065:20): [True: 32.6k, False: 32.6k]
  ------------------
 1066|  32.6k|		tag_char[tag_len] = (short_tag >> (8 * tag_len)) & 0xFF;
 1067|  32.6k|	if (!tag_len)
  ------------------
  |  Branch (1067:6): [True: 0, False: 32.6k]
  ------------------
 1068|      0|		tag_len = 1;
 1069|       |
 1070|  32.6k|	if (tag_len > 1)   {
  ------------------
  |  Branch (1070:6): [True: 0, False: 32.6k]
  ------------------
 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|  32.6k|	t = tag_char[tag_len - 1] & 0x1F;
 1083|       |
 1084|  32.6k|	switch (tag & SC_ASN1_CLASS_MASK) {
  ------------------
  |  |  136|  32.6k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
  |  Branch (1084:10): [True: 32.6k, False: 0]
  ------------------
 1085|  16.5k|	case SC_ASN1_UNI:
  ------------------
  |  |  137|  16.5k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (1085:2): [True: 16.5k, False: 16.1k]
  ------------------
 1086|  16.5k|		break;
 1087|  16.1k|	case SC_ASN1_APP:
  ------------------
  |  |  138|  16.1k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (1087:2): [True: 16.1k, False: 16.5k]
  ------------------
 1088|  16.1k|		t |= SC_ASN1_TAG_APPLICATION;
  ------------------
  |  |  186|  16.1k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
 1089|  16.1k|		break;
 1090|      0|	case SC_ASN1_CTX:
  ------------------
  |  |  139|      0|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (1090:2): [True: 0, False: 32.6k]
  ------------------
 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: 32.6k]
  ------------------
 1094|      0|		t |= SC_ASN1_TAG_PRIVATE;
  ------------------
  |  |  188|      0|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
 1095|      0|		break;
 1096|  32.6k|	}
 1097|  32.6k|	if (tag & SC_ASN1_CONS)
  ------------------
  |  |  141|  32.6k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (1097:6): [True: 6.39k, False: 26.2k]
  ------------------
 1098|  6.39k|		t |= SC_ASN1_TAG_CONSTRUCTED;
  ------------------
  |  |  190|  6.39k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
 1099|  32.6k|	if (datalen > 127) {
  ------------------
  |  Branch (1099:6): [True: 3.00k, False: 29.6k]
  ------------------
 1100|  3.00k|		c = 1;
 1101|  3.03k|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1101:10): [True: 31, False: 3.00k]
  ------------------
 1102|     31|			c++;
 1103|  3.00k|	}
 1104|       |
 1105|  32.6k|	*outlen = tag_len + 1 + c + datalen;
 1106|  32.6k|	buf = malloc(*outlen);
 1107|  32.6k|	if (buf == NULL)
  ------------------
  |  Branch (1107:6): [True: 0, False: 32.6k]
  ------------------
 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|  32.6k|	*out = p = buf;
 1111|  32.6k|	*p++ = t;
 1112|  32.6k|	for (ii=1;ii<tag_len;ii++)
  ------------------
  |  Branch (1112:12): [True: 0, False: 32.6k]
  ------------------
 1113|      0|		*p++ = tag_char[tag_len - ii - 1];
 1114|       |
 1115|  32.6k|	if (c) {
  ------------------
  |  Branch (1115:6): [True: 3.00k, False: 29.6k]
  ------------------
 1116|  3.00k|		*p++ = 0x80 | c;
 1117|  6.04k|		while (c--)
  ------------------
  |  Branch (1117:10): [True: 3.03k, False: 3.00k]
  ------------------
 1118|  3.03k|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1119|  3.00k|	}
 1120|  29.6k|	else   {
 1121|  29.6k|		*p++ = datalen & 0x7F;
 1122|  29.6k|	}
 1123|  32.6k|	if (datalen && data) {
  ------------------
  |  Branch (1123:6): [True: 31.9k, False: 752]
  |  Branch (1123:17): [True: 31.9k, False: 0]
  ------------------
 1124|  31.9k|		memcpy(p, data, datalen);
 1125|  31.9k|	}
 1126|       |
 1127|  32.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  32.6k|#define SC_SUCCESS				0
  ------------------
 1128|  32.6k|}
asn1.c:asn1_decode:
 1724|  54.8k|{
 1725|  54.8k|	int r, idx = 0;
 1726|  54.8k|	const u8 *p = in, *obj;
 1727|  54.8k|	struct sc_asn1_entry *entry = asn1;
 1728|  54.8k|	size_t left = len, objlen;
 1729|       |
 1730|  54.8k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|   109k|#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.74k, False: 48.1k]
  |  |  ------------------
  ------------------
 1731|  54.8k|		 "%*.*s""called, left=%"SC_FORMAT_LEN_SIZE_T"u, depth %d%s\n",
 1732|  54.8k|		 depth, depth, "", left, depth, choice ? ", choice" : "");
 1733|       |
 1734|  54.8k|	if (!p)
  ------------------
  |  Branch (1734:6): [True: 1, False: 54.8k]
  ------------------
 1735|      1|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      1|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1736|  54.8k|	if (left < 2) {
  ------------------
  |  Branch (1736:6): [True: 1.57k, False: 53.2k]
  ------------------
 1737|  3.59k|		while (asn1->name && (asn1->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|  2.68k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1737:10): [True: 2.68k, False: 911]
  |  Branch (1737:24): [True: 2.02k, False: 662]
  ------------------
 1738|  2.02k|			asn1++;
 1739|       |		/* If all elements were optional, there's nothing
 1740|       |		 * to complain about */
 1741|  1.57k|		if (asn1->name == NULL)
  ------------------
  |  Branch (1741:7): [True: 911, False: 662]
  ------------------
 1742|    911|			return 0;
 1743|    662|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "End of ASN.1 stream, "
  ------------------
  |  |   70|    662|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1744|    662|			      "non-optional field \"%s\" not found\n",
 1745|    662|			      asn1->name);
 1746|    662|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    662|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1747|  1.57k|	}
 1748|  53.2k|	if (p[0] == 0 || p[0] == 0xFF || len == 0)
  ------------------
  |  Branch (1748:6): [True: 1.61k, False: 51.6k]
  |  Branch (1748:19): [True: 548, False: 51.1k]
  |  Branch (1748:35): [True: 0, False: 51.1k]
  ------------------
 1749|  2.16k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  2.16k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
 1750|       |
 1751|   180k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1751:16): [True: 142k, False: 38.3k]
  ------------------
 1752|   142k|		entry = &asn1[idx];
 1753|       |
 1754|   142k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Looking for '%s', tag 0x%x%s%s\n",
  ------------------
  |  |   70|   142k|#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|   142k|			entry->name, entry->tag, choice? ", CHOICE" : "",
  |  |  |  | 1756|   142k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|   142k|#define SC_ASN1_OPTIONAL		0x00000002
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1755|   142k|			entry->name, entry->tag, choice? ", CHOICE" : "",
 1756|   142k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
 1757|       |
 1758|       |		/* Special case CHOICE has no tag */
 1759|   142k|		if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|   142k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1759:7): [True: 166, False: 142k]
  ------------------
 1760|    166|			r = asn1_decode(ctx,
 1761|    166|				(struct sc_asn1_entry *) entry->parm,
 1762|    166|				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|    166|			if (r >= 0 || (entry->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|    165|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1768:8): [True: 1, False: 165]
  |  Branch (1768:18): [True: 1, False: 164]
  ------------------
 1769|      2|				r = 0;
 1770|    166|			goto decode_ok;
 1771|    166|		}
 1772|       |
 1773|   142k|		obj = sc_asn1_skip_tag(ctx, &p, &left, entry->tag, &objlen);
 1774|   142k|		if (obj == NULL) {
  ------------------
  |  Branch (1774:7): [True: 77.2k, False: 64.9k]
  ------------------
 1775|  77.2k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "'%s' not present\n", entry->name);
  ------------------
  |  |   70|  77.2k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1776|  77.2k|			if (choice)
  ------------------
  |  Branch (1776:8): [True: 22.8k, False: 54.4k]
  ------------------
 1777|  22.8k|				continue;
 1778|  54.4k|			if (entry->flags & SC_ASN1_OPTIONAL)
  ------------------
  |  |  148|  54.4k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1778:8): [True: 49.7k, False: 4.76k]
  ------------------
 1779|  49.7k|				continue;
 1780|  4.76k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "mandatory ASN.1 object '%s' not found\n", entry->name);
  ------------------
  |  |   70|  4.76k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1781|  4.76k|			if (left) {
  ------------------
  |  Branch (1781:8): [True: 4.65k, False: 110]
  ------------------
 1782|  4.65k|				u8 line[128], *linep = line;
 1783|  4.65k|				size_t i;
 1784|       |
 1785|  4.65k|				line[0] = 0;
 1786|  45.6k|				for (i = 0; i < 10 && i < left; i++) {
  ------------------
  |  Branch (1786:17): [True: 41.8k, False: 3.82k]
  |  Branch (1786:27): [True: 41.0k, False: 837]
  ------------------
 1787|  41.0k|					sprintf((char *) linep, "%02X ", p[i]);
 1788|  41.0k|					linep += 3;
 1789|  41.0k|				}
 1790|  4.65k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "next tag: %s\n", line);
  ------------------
  |  |   70|  4.65k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1791|  4.65k|			}
 1792|  4.76k|			sc_free_entry(asn1);
 1793|  4.76k|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|  4.76k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  4.76k|	int _ret = r; \
  |  |  155|  4.76k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 4.76k, False: 0]
  |  |  ------------------
  |  |  156|  4.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|  4.76k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4.76k, False: 0]
  |  |  ------------------
  |  |  157|  4.76k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  4.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|  4.76k|	return _ret; \
  |  |  163|  4.76k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1794|  4.76k|		}
 1795|  64.9k|		r = asn1_decode_entry(ctx, entry, obj, objlen, depth);
 1796|       |
 1797|  65.1k|decode_ok:
 1798|  65.1k|		if (r)
  ------------------
  |  Branch (1798:7): [True: 1.93k, False: 63.1k]
  ------------------
 1799|  1.93k|			return r;
 1800|  63.1k|		if (choice)
  ------------------
  |  Branch (1800:7): [True: 6.06k, False: 57.1k]
  ------------------
 1801|  6.06k|			break;
 1802|  63.1k| 	}
 1803|  44.4k| 	if (choice && asn1[idx].name == NULL) /* No match */
  ------------------
  |  Branch (1803:7): [True: 6.36k, False: 38.0k]
  |  Branch (1803:17): [True: 303, False: 6.06k]
  ------------------
 1804|    303|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|    303|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    303|	int _ret = r; \
  |  |  155|    303|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 303, False: 0]
  |  |  ------------------
  |  |  156|    303|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    303|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 303, False: 0]
  |  |  ------------------
  |  |  157|    303|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    303|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    303|	return _ret; \
  |  |  163|    303|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1805|  44.1k| 	if (newp != NULL)
  ------------------
  |  Branch (1805:7): [True: 10.0k, False: 34.0k]
  ------------------
 1806|  10.0k|		*newp = p;
 1807|  44.1k| 	if (len_left != NULL)
  ------------------
  |  Branch (1807:7): [True: 10.0k, False: 34.0k]
  ------------------
 1808|  10.0k|		*len_left = left;
 1809|  44.1k|	if (choice)
  ------------------
  |  Branch (1809:6): [True: 6.06k, False: 38.0k]
  ------------------
 1810|  6.06k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, idx);
  ------------------
  |  |  153|  6.06k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  6.06k|	int _ret = r; \
  |  |  155|  6.06k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.21k, False: 4.84k]
  |  |  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 1.21k]
  |  |  ------------------
  |  |  157|  1.21k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  4.84k|	} else { \
  |  |  159|  4.84k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|  4.84k|			"returning with: %d\n", _ret); \
  |  |  161|  4.84k|	} \
  |  |  162|  6.06k|	return _ret; \
  |  |  163|  6.06k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1811|  38.0k|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, 0);
  ------------------
  |  |  153|  38.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  38.0k|	int _ret = r; \
  |  |  155|  38.0k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 38.0k, False: 0]
  |  |  ------------------
  |  |  156|  38.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 38.0k]
  |  |  ------------------
  |  |  157|  38.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  38.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|  38.0k|	return _ret; \
  |  |  163|  38.0k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1812|  38.0k|}
asn1.c:sc_free_entry:
 1689|  13.2k|static void sc_free_entry(struct sc_asn1_entry *asn1) {
 1690|  13.2k|	int idx = 0;
 1691|  13.2k|	struct sc_asn1_entry *entry = asn1;
 1692|       |
 1693|  13.2k|	if (!asn1)
  ------------------
  |  Branch (1693:6): [True: 607, False: 12.6k]
  ------------------
 1694|    607|		return;
 1695|       |
 1696|  58.3k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1696:16): [True: 45.6k, False: 12.6k]
  ------------------
 1697|  45.6k|		entry = &asn1[idx];
 1698|  45.6k|		switch (entry->type) {
 1699|  2.62k|		case SC_ASN1_CHOICE:
  ------------------
  |  |  170|  2.62k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1699:3): [True: 2.62k, False: 43.0k]
  ------------------
 1700|  8.51k|		case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  8.51k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1700:3): [True: 5.89k, False: 39.7k]
  ------------------
 1701|  8.51k|			sc_free_entry((struct sc_asn1_entry *) entry->parm);
 1702|  8.51k|			break;
 1703|  13.7k|		case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  13.7k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1703:3): [True: 13.7k, False: 31.8k]
  ------------------
 1704|  13.7k|		case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  13.7k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1704:3): [True: 47, False: 45.5k]
  ------------------
 1705|  13.8k|		case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  13.8k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1705:3): [True: 82, False: 45.5k]
  ------------------
 1706|  14.0k|		case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|  14.0k|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1706:3): [True: 162, False: 45.4k]
  ------------------
 1707|  14.2k|		case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|  14.2k|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1707:3): [True: 241, False: 45.4k]
  ------------------
 1708|  15.6k|		case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  15.6k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1708:3): [True: 1.40k, False: 44.2k]
  ------------------
 1709|  15.6k|			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  149|  15.6k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
              			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  1.48k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1709:8): [True: 1.48k, False: 14.1k]
  |  Branch (1709:42): [True: 516, False: 969]
  ------------------
 1710|    516|				u8 **buf = (u8 **)entry->parm;
 1711|    516|				free(*buf);
 1712|    516|				*buf = NULL;
 1713|    516|			}
 1714|  15.6k|			break;
 1715|  21.4k|		default:
  ------------------
  |  Branch (1715:3): [True: 21.4k, False: 24.1k]
  ------------------
 1716|  21.4k|			break;
 1717|  45.6k|		}
 1718|  45.6k|	}
 1719|  12.6k|}
asn1.c:asn1_decode_entry:
 1491|  64.9k|{
 1492|  64.9k|	void *parm = entry->parm;
 1493|  64.9k|	int (*callback_func)(sc_context_t *nctx, void *arg, const u8 *nobj,
 1494|  64.9k|			     size_t nobjlen, int ndepth);
 1495|  64.9k|	size_t *len = (size_t *) entry->arg;
 1496|  64.9k|	int r = 0;
 1497|       |
 1498|  64.9k|	callback_func = parm;
 1499|       |
 1500|  64.9k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s', raw data:%s%s\n",
  ------------------
  |  |   70|   259k|#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: 18.5k, False: 46.3k]
  |  |  |  Branch (70:115): [True: 18.5k, False: 46.3k]
  |  |  ------------------
  ------------------
 1501|  64.9k|		depth, depth, "", entry->name,
 1502|  64.9k|		sc_dump_hex(obj, objlen > 16  ? 16 : objlen),
 1503|  64.9k|		objlen > 16 ? "..." : "");
 1504|       |
 1505|  64.9k|	switch (entry->type) {
 1506|  17.0k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  17.0k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1506:2): [True: 17.0k, False: 47.8k]
  ------------------
 1507|  17.0k|		if (parm != NULL)
  ------------------
  |  Branch (1507:7): [True: 11.8k, False: 5.27k]
  ------------------
 1508|  11.8k|			r = asn1_decode(ctx, (struct sc_asn1_entry *) parm, obj,
 1509|  11.8k|				       objlen, NULL, NULL, 0, depth + 1);
 1510|  17.0k|		break;
 1511|  1.82k|	case SC_ASN1_NULL:
  ------------------
  |  |  158|  1.82k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1511:2): [True: 1.82k, False: 63.1k]
  ------------------
 1512|  1.82k|		break;
 1513|     54|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|     54|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1513:2): [True: 54, False: 64.9k]
  ------------------
 1514|     54|		if (parm != NULL) {
  ------------------
  |  Branch (1514:7): [True: 54, False: 0]
  ------------------
 1515|     54|			if (objlen != 1) {
  ------------------
  |  Branch (1515:8): [True: 6, False: 48]
  ------------------
 1516|      6|				sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1517|      6|					 "invalid ASN.1 object length: %"SC_FORMAT_LEN_SIZE_T"u\n",
 1518|      6|					 objlen);
 1519|      6|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1520|      6|			} else
 1521|     48|				*((int *) parm) = obj[0] ? 1 : 0;
  ------------------
  |  Branch (1521:23): [True: 47, False: 1]
  ------------------
 1522|     54|		}
 1523|     54|		break;
 1524|  3.14k|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|  3.14k|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1524:2): [True: 3.14k, False: 61.8k]
  ------------------
 1525|  3.14k|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|  3.14k|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1525:2): [True: 0, False: 64.9k]
  ------------------
 1526|  3.14k|		if (parm != NULL) {
  ------------------
  |  Branch (1526:7): [True: 3.14k, False: 0]
  ------------------
 1527|  3.14k|			r = sc_asn1_decode_integer(obj, objlen, (int *) entry->parm, 0);
 1528|  3.14k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  3.14k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1528:8): [True: 3.12k, False: 14]
  ------------------
 1529|  3.12k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s' returned %d\n",
  ------------------
  |  |   70|  3.12k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1530|  3.12k|						depth, depth, "", entry->name, *((int *)entry->parm));
 1531|  3.12k|			}
 1532|  3.14k|		}
 1533|  3.14k|		break;
 1534|  2.35k|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  2.35k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1534:2): [True: 2.35k, False: 62.6k]
  ------------------
 1535|  4.34k|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  4.34k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1535:2): [True: 1.98k, False: 62.9k]
  ------------------
 1536|  4.34k|		if (parm != NULL) {
  ------------------
  |  Branch (1536:7): [True: 2.35k, False: 1.98k]
  ------------------
 1537|  2.35k|			int invert = entry->type == SC_ASN1_BIT_STRING ? 1 : 0;
  ------------------
  |  |  155|  2.35k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1537:17): [True: 0, False: 2.35k]
  ------------------
 1538|  2.35k|			if (len == NULL)
  ------------------
  |  Branch (1538:8): [True: 0, False: 2.35k]
  ------------------
 1539|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1540|  2.35k|			if (objlen < 1) {
  ------------------
  |  Branch (1540:8): [True: 10, False: 2.34k]
  ------------------
 1541|     10|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     10|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1542|     10|				break;
 1543|     10|			}
 1544|  2.34k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  2.34k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1544:8): [True: 2.34k, False: 0]
  ------------------
 1545|  2.34k|				u8 **buf = (u8 **) parm;
 1546|  2.34k|				if (objlen > 1) {
  ------------------
  |  Branch (1546:9): [True: 2.30k, False: 34]
  ------------------
 1547|  2.30k|					*buf = malloc(objlen-1);
 1548|  2.30k|					if (*buf == NULL) {
  ------------------
  |  Branch (1548:10): [True: 0, False: 2.30k]
  ------------------
 1549|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1550|      0|						break;
 1551|      0|					}
 1552|  2.30k|				}
 1553|  2.34k|				*len = objlen-1;
 1554|  2.34k|				parm = *buf;
 1555|  2.34k|			}
 1556|  2.34k|			r = decode_bit_string(obj, objlen, (u8 *) parm, *len, invert, 0);
 1557|  2.34k|			if (r >= 0) {
  ------------------
  |  Branch (1557:8): [True: 2.31k, False: 29]
  ------------------
 1558|  2.31k|				*len = r;
 1559|  2.31k|				r = 0;
 1560|  2.31k|			}
 1561|  2.34k|		}
 1562|  4.33k|		break;
 1563|  4.33k|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|    520|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1563:2): [True: 520, False: 64.4k]
  ------------------
 1564|    520|		if (parm != NULL)
  ------------------
  |  Branch (1564:7): [True: 520, False: 0]
  ------------------
 1565|    520|			r = decode_bit_field(obj, objlen, (u8 *) parm, *len, 0);
 1566|    520|		break;
 1567|  19.7k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  19.7k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1567:2): [True: 19.7k, False: 45.2k]
  ------------------
 1568|  19.7k|		if (parm != NULL) {
  ------------------
  |  Branch (1568:7): [True: 19.6k, False: 66]
  ------------------
 1569|  19.6k|			size_t c;
 1570|  19.6k|			if (len == NULL)
  ------------------
  |  Branch (1570:8): [True: 0, False: 19.6k]
  ------------------
 1571|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1572|       |
 1573|       |			/* Strip off padding zero */
 1574|  19.6k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  19.6k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1574:8): [True: 4.13k, False: 15.5k]
  ------------------
 1575|  4.13k|					&& objlen > 1 && obj[0] == 0x00) {
  ------------------
  |  Branch (1575:9): [True: 3.79k, False: 342]
  |  Branch (1575:23): [True: 2.56k, False: 1.23k]
  ------------------
 1576|  2.56k|				objlen--;
 1577|  2.56k|				obj++;
 1578|  2.56k|			}
 1579|       |
 1580|       |			/* Allocate buffer if needed */
 1581|  19.6k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  19.6k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1581:8): [True: 12.6k, False: 6.99k]
  ------------------
 1582|  12.6k|				u8 **buf = (u8 **) parm;
 1583|  12.6k|				if (objlen > 0) {
  ------------------
  |  Branch (1583:9): [True: 9.40k, False: 3.27k]
  ------------------
 1584|  9.40k|					*buf = malloc(objlen);
 1585|  9.40k|					if (*buf == NULL) {
  ------------------
  |  Branch (1585:10): [True: 0, False: 9.40k]
  ------------------
 1586|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1587|      0|						break;
 1588|      0|					}
 1589|  9.40k|				}
 1590|  12.6k|				c = *len = objlen;
 1591|  12.6k|				parm = *buf;
 1592|  12.6k|			} else
 1593|  6.99k|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1593:9): [True: 241, False: 6.75k]
  ------------------
 1594|       |
 1595|  19.6k|			memcpy(parm, obj, c);
 1596|  19.6k|			*len = c;
 1597|  19.6k|		}
 1598|  19.7k|		break;
 1599|  19.7k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|     13|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1599:2): [True: 13, False: 64.9k]
  ------------------
 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|  5.60k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  5.60k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1622:2): [True: 5.60k, False: 59.3k]
  ------------------
 1623|  5.60k|		if (parm != NULL)
  ------------------
  |  Branch (1623:7): [True: 5.60k, False: 5]
  ------------------
 1624|  5.60k|			r = sc_asn1_decode_object_id(obj, objlen, (struct sc_object_id *) parm);
 1625|  5.60k|		break;
 1626|      8|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      8|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1626:2): [True: 8, False: 64.9k]
  ------------------
 1627|    271|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|    271|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1627:2): [True: 263, False: 64.7k]
  ------------------
 1628|    271|		if (parm != NULL) {
  ------------------
  |  Branch (1628:7): [True: 267, False: 4]
  ------------------
 1629|    267|			if (len == NULL)
  ------------------
  |  Branch (1629:8): [True: 0, False: 267]
  ------------------
 1630|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1631|    267|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    267|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1631:8): [True: 0, False: 267]
  ------------------
 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|    267|			r = sc_asn1_decode_utf8string(obj, objlen, (u8 *) parm, len);
 1642|    267|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    267|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1642:8): [True: 0, False: 267]
  ------------------
 1643|      0|				*len -= 1;
 1644|      0|			}
 1645|    267|		}
 1646|    271|		break;
 1647|  5.17k|	case SC_ASN1_PATH:
  ------------------
  |  |  174|  5.17k|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1647:2): [True: 5.17k, False: 59.7k]
  ------------------
 1648|  5.17k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1648:7): [True: 5.16k, False: 6]
  ------------------
 1649|  5.16k|			r = asn1_decode_path(ctx, obj, objlen, (sc_path_t *) parm, depth);
 1650|  5.17k|		break;
 1651|     32|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|     32|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1651:2): [True: 32, False: 64.9k]
  ------------------
 1652|     32|		if (entry->parm != NULL) {
  ------------------
  |  Branch (1652:7): [True: 32, False: 0]
  ------------------
 1653|     32|			struct sc_pkcs15_id *id = (struct sc_pkcs15_id *) parm;
 1654|     32|			size_t c = objlen > sizeof(id->value) ? sizeof(id->value) : objlen;
  ------------------
  |  Branch (1654:15): [True: 0, False: 32]
  ------------------
 1655|       |
 1656|     32|			memcpy(id->value, obj, c);
 1657|     32|			id->len = c;
 1658|     32|		}
 1659|     32|		break;
 1660|     71|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|     71|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1660:2): [True: 71, False: 64.8k]
  ------------------
 1661|     71|		if (entry->parm != NULL)
  ------------------
  |  Branch (1661:7): [True: 70, False: 1]
  ------------------
 1662|     70|			r = asn1_decode_p15_object(ctx, obj, objlen, (struct sc_asn1_pkcs15_object *) parm, depth);
 1663|     71|		break;
 1664|  4.53k|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|  4.53k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1664:2): [True: 4.53k, False: 60.4k]
  ------------------
 1665|  4.53k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1665:7): [True: 4.53k, False: 0]
  ------------------
 1666|  4.53k|			r = sc_asn1_decode_algorithm_id(ctx, obj, objlen, (struct sc_algorithm_id *) parm, depth);
 1667|  4.53k|		break;
 1668|     35|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|     35|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1668:2): [True: 35, False: 64.9k]
  ------------------
 1669|     35|		if (entry->parm != NULL)
  ------------------
  |  Branch (1669:7): [True: 35, False: 0]
  ------------------
 1670|     35|			r = asn1_decode_se_info(ctx, obj, objlen, (sc_pkcs15_sec_env_info_t ***)entry->parm, len, depth);
 1671|     35|		break;
 1672|  2.53k|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|  2.53k|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1672:2): [True: 2.53k, False: 62.4k]
  ------------------
 1673|  2.53k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1673:7): [True: 2.53k, False: 0]
  ------------------
 1674|  2.53k|			r = callback_func(ctx, entry->arg, obj, objlen, depth);
 1675|  2.53k|		break;
 1676|      0|	default:
  ------------------
  |  Branch (1676:2): [True: 0, False: 64.9k]
  ------------------
 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|  64.9k|	}
 1680|  64.9k|	if (r) {
  ------------------
  |  Branch (1680:6): [True: 1.76k, False: 63.1k]
  ------------------
 1681|  1.76k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|  1.76k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1682|  1.76k|		      sc_strerror(r));
 1683|  1.76k|		return r;
 1684|  1.76k|	}
 1685|  63.1k|	entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  63.1k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
 1686|  63.1k|	return 0;
 1687|  64.9k|}
asn1.c:decode_bit_field:
  692|    520|{
  693|    520|	u8		data[sizeof(unsigned int)];
  694|    520|	unsigned int	field = 0;
  695|    520|	int		i, n;
  696|       |
  697|    520|	if (outlen != sizeof(data))
  ------------------
  |  Branch (697:6): [True: 0, False: 520]
  ------------------
  698|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  699|       |
  700|    520|	n = decode_bit_string(inbuf, inlen, data, sizeof(data), 1, strict);
  701|    520|	if (n < 0)
  ------------------
  |  Branch (701:6): [True: 30, False: 490]
  ------------------
  702|     30|		return n;
  703|       |
  704|  1.30k|	for (i = 0; i < n; i += 8) {
  ------------------
  |  Branch (704:14): [True: 812, False: 490]
  ------------------
  705|    812|		field |= ((unsigned int) data[i/8] << i);
  706|    812|	}
  707|    490|	memcpy(outbuf, &field, outlen);
  708|    490|	return 0;
  709|    520|}
asn1.c:sc_asn1_decode_utf8string:
  968|    267|{
  969|    267|	if (inlen+1 > *outlen)
  ------------------
  |  Branch (969:6): [True: 3, False: 264]
  ------------------
  970|      3|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      3|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  971|    264|	*outlen = inlen+1;
  972|    264|	memcpy(out, inbuf, inlen);
  973|    264|	out[inlen] = 0;
  974|    264|	return 0;
  975|    267|}
asn1.c:asn1_decode_path:
 1150|  5.16k|{
 1151|  5.16k|	int idx, count, r;
 1152|  5.16k|	struct sc_asn1_entry asn1_path_ext[3], asn1_path[5];
 1153|  5.16k|	unsigned char path_value[SC_MAX_PATH_SIZE], aid_value[SC_MAX_AID_SIZE];
 1154|  5.16k|	size_t path_len = sizeof(path_value), aid_len = sizeof(aid_value);
 1155|       |
 1156|  5.16k|	memset(path, 0, sizeof(struct sc_path));
 1157|       |
 1158|  5.16k|	sc_copy_asn1_entry(c_asn1_path_ext, asn1_path_ext);
 1159|  5.16k|	sc_copy_asn1_entry(c_asn1_path, asn1_path);
 1160|       |
 1161|  5.16k|	sc_format_asn1_entry(asn1_path_ext + 0, aid_value, &aid_len, 0);
 1162|  5.16k|	sc_format_asn1_entry(asn1_path_ext + 1, path_value, &path_len, 0);
 1163|       |
 1164|  5.16k|	sc_format_asn1_entry(asn1_path + 0, path_value, &path_len, 0);
 1165|  5.16k|	sc_format_asn1_entry(asn1_path + 1, &idx, NULL, 0);
 1166|  5.16k|	sc_format_asn1_entry(asn1_path + 2, &count, NULL, 0);
 1167|  5.16k|	sc_format_asn1_entry(asn1_path + 3, asn1_path_ext, NULL, 0);
 1168|       |
 1169|  5.16k|	r = asn1_decode(ctx, asn1_path, in, len, NULL, NULL, 0, depth + 1);
 1170|  5.16k|	if (r)
  ------------------
  |  Branch (1170:6): [True: 11, False: 5.15k]
  ------------------
 1171|     11|		return r;
 1172|       |
 1173|  5.15k|	if (asn1_path[3].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|  5.15k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1173:6): [True: 0, False: 5.15k]
  ------------------
 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|  5.15k|	else if (asn1_path[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|  5.15k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1181:11): [True: 5.12k, False: 35]
  ------------------
 1182|       |		/* path present: set 'path' */
 1183|  5.12k|		memcpy(path->value, path_value, path_len);
 1184|  5.12k|		path->len = path_len;
 1185|  5.12k|	}
 1186|     35|	else   {
 1187|       |		/* failed if both 'path' and 'pathExtended' are absent */
 1188|     35|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|     35|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1189|     35|	}
 1190|       |
 1191|  5.12k|	if (path->len == 2)
  ------------------
  |  Branch (1191:6): [True: 1.83k, False: 3.29k]
  ------------------
 1192|  1.83k|		path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  1.83k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1193|  3.29k|	else   if (path->aid.len && path->len > 2)
  ------------------
  |  Branch (1193:13): [True: 0, False: 3.29k]
  |  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.29k|	else
 1196|  3.29k|		path->type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  3.29k|#define SC_PATH_TYPE_PATH		2
  ------------------
 1197|       |
 1198|  5.12k|	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  5.12k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  1.86k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1198:6): [True: 1.86k, False: 3.25k]
  |  Branch (1198:48): [True: 3, False: 1.86k]
  ------------------
 1199|      3|		path->index = idx;
 1200|      3|		path->count = count;
 1201|      3|	}
 1202|  5.11k|	else {
 1203|  5.11k|		path->index = 0;
 1204|  5.11k|		path->count = -1;
 1205|  5.11k|	}
 1206|       |
 1207|  5.12k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.12k|#define SC_SUCCESS				0
  ------------------
 1208|  5.15k|}
asn1.c:asn1_decode_p15_object:
 1396|     70|{
 1397|     70|	struct sc_pkcs15_object *p15_obj = obj->p15_obj;
 1398|     70|	struct sc_asn1_entry asn1_c_attr[6], asn1_p15_obj[5];
 1399|     70|	struct sc_asn1_entry asn1_ac_rules[SC_PKCS15_MAX_ACCESS_RULES + 1], asn1_ac_rule[SC_PKCS15_MAX_ACCESS_RULES][3];
 1400|     70|	size_t flags_len = sizeof(p15_obj->flags);
 1401|     70|	size_t label_len = sizeof(p15_obj->label);
 1402|     70|	size_t access_mode_len = sizeof(p15_obj->access_rules[0].access_mode);
 1403|     70|	int r, ii;
 1404|       |
 1405|    630|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)
  ------------------
  |  |   42|    630|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1405:13): [True: 560, False: 70]
  ------------------
 1406|    560|		sc_copy_asn1_entry(c_asn1_access_control_rule, asn1_ac_rule[ii]);
 1407|     70|	sc_copy_asn1_entry(c_asn1_access_control_rules, asn1_ac_rules);
 1408|       |
 1409|       |
 1410|     70|	sc_copy_asn1_entry(c_asn1_com_obj_attr, asn1_c_attr);
 1411|     70|	sc_copy_asn1_entry(c_asn1_p15_obj, asn1_p15_obj);
 1412|     70|	sc_format_asn1_entry(asn1_c_attr + 0, p15_obj->label, &label_len, 0);
 1413|     70|	sc_format_asn1_entry(asn1_c_attr + 1, &p15_obj->flags, &flags_len, 0);
 1414|     70|	sc_format_asn1_entry(asn1_c_attr + 2, &p15_obj->auth_id, NULL, 0);
 1415|     70|	sc_format_asn1_entry(asn1_c_attr + 3, &p15_obj->user_consent, NULL, 0);
 1416|       |
 1417|    630|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)   {
  ------------------
  |  |   42|    630|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1417:13): [True: 560, False: 70]
  ------------------
 1418|    560|		sc_format_asn1_entry(asn1_ac_rule[ii] + 0, &p15_obj->access_rules[ii].access_mode, &access_mode_len, 0);
 1419|    560|		sc_format_asn1_entry(asn1_ac_rule[ii] + 1, &p15_obj->access_rules[ii].auth_id, NULL, 0);
 1420|    560|		sc_format_asn1_entry(asn1_ac_rules + ii, asn1_ac_rule[ii], NULL, 0);
 1421|    560|	}
 1422|     70|	sc_format_asn1_entry(asn1_c_attr + 4, asn1_ac_rules, NULL, 0);
 1423|       |
 1424|     70|	sc_format_asn1_entry(asn1_p15_obj + 0, asn1_c_attr, NULL, 0);
 1425|     70|	sc_format_asn1_entry(asn1_p15_obj + 1, obj->asn1_class_attr, NULL, 0);
 1426|     70|	sc_format_asn1_entry(asn1_p15_obj + 2, obj->asn1_subclass_attr, NULL, 0);
 1427|     70|	sc_format_asn1_entry(asn1_p15_obj + 3, obj->asn1_type_attr, NULL, 0);
 1428|       |
 1429|     70|	r = asn1_decode(ctx, asn1_p15_obj, in, len, NULL, NULL, 0, depth + 1);
 1430|     70|	return r;
 1431|     70|}
asn1.c:asn1_decode_se_info:
 1244|     35|{
 1245|     35|	struct sc_pkcs15_sec_env_info **ses;
 1246|     35|	const unsigned char *ptr = obj;
 1247|     35|	size_t idx, ptrlen = objlen;
 1248|     35|	int ret;
 1249|       |
 1250|     35|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     35|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     35|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     35|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     35|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1251|       |
 1252|     35|	ses = calloc(SC_MAX_SE_NUM, sizeof(sc_pkcs15_sec_env_info_t *));
  ------------------
  |  |   51|     35|#define SC_MAX_SE_NUM			8
  ------------------
 1253|     35|	if (ses == NULL) {
  ------------------
  |  Branch (1253:6): [True: 0, False: 35]
  ------------------
 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|     45|	for (idx=0; idx < SC_MAX_SE_NUM && ptrlen; )   {
  ------------------
  |  |   51|     90|#define SC_MAX_SE_NUM			8
  ------------------
  |  Branch (1257:14): [True: 45, False: 0]
  |  Branch (1257:37): [True: 18, False: 27]
  ------------------
 1258|     18|		struct sc_asn1_entry asn1_se[2];
 1259|     18|		struct sc_asn1_entry asn1_se_info[4];
 1260|     18|		struct sc_pkcs15_sec_env_info si;
 1261|       |
 1262|     18|		sc_copy_asn1_entry(c_asn1_se, asn1_se);
 1263|     18|		sc_copy_asn1_entry(c_asn1_se_info, asn1_se_info);
 1264|       |
 1265|     18|		si.aid.len = sizeof(si.aid.value);
 1266|     18|		sc_format_asn1_entry(asn1_se_info + 0, &si.se, NULL, 0);
 1267|     18|		sc_format_asn1_entry(asn1_se_info + 1, &si.owner, NULL, 0);
 1268|     18|		sc_format_asn1_entry(asn1_se_info + 2, &si.aid.value, &si.aid.len, 0);
 1269|     18|		sc_format_asn1_entry(asn1_se + 0, asn1_se_info, NULL, 0);
 1270|       |
 1271|     18|		ret = asn1_decode(ctx, asn1_se, ptr, ptrlen, &ptr, &ptrlen, 0, depth+1);
 1272|     18|		if (ret != SC_SUCCESS)
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
  |  Branch (1272:7): [True: 8, False: 10]
  ------------------
 1273|      8|			goto err;
 1274|     10|		if (!(asn1_se_info[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|     10|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1274:7): [True: 5, False: 5]
  ------------------
 1275|      5|			sc_init_oid(&si.owner);
 1276|       |
 1277|     10|		ses[idx] = calloc(1, sizeof(sc_pkcs15_sec_env_info_t));
 1278|     10|		if (ses[idx] == NULL) {
  ------------------
  |  Branch (1278:7): [True: 0, False: 10]
  ------------------
 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|     10|		memcpy(ses[idx], &si, sizeof(struct sc_pkcs15_sec_env_info));
 1284|     10|		idx++;
 1285|     10|	}
 1286|       |
 1287|     27|	*se  = ses;
 1288|     27|	*num = idx;
 1289|     27|	ret = SC_SUCCESS;
  ------------------
  |  |   28|     27|#define SC_SUCCESS				0
  ------------------
 1290|     35|err:
 1291|     35|	if (ret != SC_SUCCESS) {
  ------------------
  |  |   28|     35|#define SC_SUCCESS				0
  ------------------
  |  Branch (1291:6): [True: 8, False: 27]
  ------------------
 1292|      8|		size_t i;
 1293|     13|		for (i = 0; i < idx; i++)
  ------------------
  |  Branch (1293:15): [True: 5, False: 8]
  ------------------
 1294|      5|			if (ses[i])
  ------------------
  |  Branch (1294:8): [True: 5, False: 0]
  ------------------
 1295|      5|				free(ses[i]);
 1296|      8|		free(ses);
 1297|      8|	}
 1298|       |
 1299|     35|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, ret);
  ------------------
  |  |  153|     35|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     35|	int _ret = r; \
  |  |  155|     35|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 35, False: 0]
  |  |  ------------------
  |  |  156|     35|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 8, False: 27]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1300|     35|}
asn1.c:asn1_encode:
 2045|  29.5k|{
 2046|  29.5k|	int r, idx = 0;
 2047|  29.5k|	u8 *obj = NULL, *buf = NULL, *tmp;
 2048|  29.5k|	size_t total = 0, objsize;
 2049|       |
 2050|  29.5k|	if (asn1 == NULL) {
  ------------------
  |  Branch (2050:6): [True: 0, False: 29.5k]
  ------------------
 2051|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2052|      0|	}
 2053|       |
 2054|  79.3k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (2054:16): [True: 49.8k, False: 29.5k]
  ------------------
 2055|  49.8k|		r = asn1_encode_entry(ctx, &asn1[idx], &obj, &objsize, depth);
 2056|  49.8k|		if (r) {
  ------------------
  |  Branch (2056:7): [True: 30, False: 49.7k]
  ------------------
 2057|     30|			if (obj)
  ------------------
  |  Branch (2057:8): [True: 0, False: 30]
  ------------------
 2058|      0|				free(obj);
 2059|     30|			if (buf)
  ------------------
  |  Branch (2059:8): [True: 10, False: 20]
  ------------------
 2060|     10|				free(buf);
 2061|     30|			return r;
 2062|     30|		}
 2063|       |		/* in case of an empty (optional) element continue with
 2064|       |		 * the next asn1 element */
 2065|  49.7k|		if (!objsize)
  ------------------
  |  Branch (2065:7): [True: 17.0k, False: 32.6k]
  ------------------
 2066|  17.0k|			continue;
 2067|  32.6k|		tmp = (u8 *) realloc(buf, total + objsize);
 2068|  32.6k|		if (!tmp) {
  ------------------
  |  Branch (2068:7): [True: 0, False: 32.6k]
  ------------------
 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|  32.6k|		buf = tmp;
 2076|  32.6k|		memcpy(buf + total, obj, objsize);
 2077|  32.6k|		free(obj);
 2078|  32.6k|		obj = NULL;
 2079|  32.6k|		total += objsize;
 2080|  32.6k|	}
 2081|  29.5k|	*ptr = buf;
 2082|  29.5k|	*size = total;
 2083|  29.5k|	return 0;
 2084|  29.5k|}
asn1.c:asn1_encode_entry:
 1828|  49.8k|{
 1829|  49.8k|	void *parm = entry->parm;
 1830|  49.8k|	int (*callback_func)(sc_context_t *nctx, void *arg, u8 **nobj,
 1831|  49.8k|			     size_t *nobjlen, int ndepth);
 1832|  49.8k|	const size_t *len = (const size_t *) entry->arg;
 1833|  49.8k|	int r = 0;
 1834|  49.8k|	u8 * buf = NULL;
 1835|  49.8k|	size_t buflen = 0;
 1836|       |
 1837|  49.8k|	callback_func = parm;
 1838|       |
 1839|  49.8k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sencoding '%s'%s\n",
  ------------------
  |  |   70|  49.8k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               #define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  | 1840|  49.8k|	       	depth, depth, "", entry->name,
  |  |  |  | 1841|  49.8k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|  49.8k|#define SC_ASN1_PRESENT			0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1840|  49.8k|	       	depth, depth, "", entry->name,
 1841|  49.8k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
 1842|  49.8k|	if (!(entry->flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  49.8k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1842:6): [True: 17.0k, False: 32.7k]
  ------------------
 1843|  17.0k|		goto no_object;
 1844|  32.7k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|  65.4k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 23.3k, False: 9.34k]
  |  |  ------------------
  ------------------
 1845|  32.7k|		 "%*.*stype=%d, tag=0x%02x, parm=%p, len=%"SC_FORMAT_LEN_SIZE_T"u\n",
 1846|  32.7k|		 depth, depth, "", entry->type, entry->tag, parm,
 1847|  32.7k|		 len ? *len : 0);
 1848|       |
 1849|  32.7k|	if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|  32.7k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1849:6): [True: 0, False: 32.7k]
  ------------------
 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|  32.7k|	if (entry->type != SC_ASN1_NULL && parm == NULL) {
  ------------------
  |  |  158|  65.4k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1874:6): [True: 31.9k, False: 752]
  |  Branch (1874:37): [True: 11, False: 31.9k]
  ------------------
 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|  32.7k|	switch (entry->type) {
 1880|  2.44k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  2.44k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1880:2): [True: 2.44k, False: 30.2k]
  ------------------
 1881|  2.44k|		r = asn1_encode(ctx, (const struct sc_asn1_entry *) parm, &buf,
 1882|  2.44k|				&buflen, depth + 1);
 1883|  2.44k|		break;
 1884|    752|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    752|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1884:2): [True: 752, False: 31.9k]
  ------------------
 1885|    752|		buf = NULL;
 1886|    752|		buflen = 0;
 1887|    752|		break;
 1888|      0|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|      0|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1888:2): [True: 0, False: 32.7k]
  ------------------
 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: 32.7k]
  ------------------
 1898|      0|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|      0|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1898:2): [True: 0, False: 32.7k]
  ------------------
 1899|      0|		r = asn1_encode_integer(*((int *) entry->parm), &buf, &buflen);
 1900|      0|		break;
 1901|  1.63k|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  1.63k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1901:2): [True: 1.63k, False: 31.0k]
  ------------------
 1902|  1.63k|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  1.63k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1902:2): [True: 0, False: 32.7k]
  ------------------
 1903|  1.63k|		if (len != NULL) {
  ------------------
  |  Branch (1903:7): [True: 1.63k, False: 0]
  ------------------
 1904|  1.63k|			if (entry->type == SC_ASN1_BIT_STRING)
  ------------------
  |  |  155|  1.63k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1904:8): [True: 0, False: 1.63k]
  ------------------
 1905|      0|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 1);
 1906|  1.63k|			else
 1907|  1.63k|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 0);
 1908|  1.63k|		} else {
 1909|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1910|      0|		}
 1911|  1.63k|		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: 32.7k]
  ------------------
 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: 32.7k]
  ------------------
 1920|  21.7k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  21.7k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1920:2): [True: 21.7k, False: 10.9k]
  ------------------
 1921|  21.7k|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  21.7k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1921:2): [True: 0, False: 32.7k]
  ------------------
 1922|  21.7k|		if (len != NULL) {
  ------------------
  |  Branch (1922:7): [True: 21.7k, False: 0]
  ------------------
 1923|  21.7k|			buf = malloc(*len + 1);
 1924|  21.7k|			if (buf == NULL) {
  ------------------
  |  Branch (1924:8): [True: 0, False: 21.7k]
  ------------------
 1925|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1926|      0|				break;
 1927|      0|			}
 1928|  21.7k|			buflen = 0;
 1929|       |			/* If the integer is supposed to be unsigned, insert
 1930|       |			 * a padding byte if the MSB is one */
 1931|  21.7k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  21.7k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1931:8): [True: 1.61k, False: 20.1k]
  ------------------
 1932|  1.61k|					&& (((u8 *) parm)[0] & 0x80)) {
  ------------------
  |  Branch (1932:9): [True: 438, False: 1.17k]
  ------------------
 1933|    438|				buf[buflen++] = 0x00;
 1934|    438|			}
 1935|  21.7k|			memcpy(buf + buflen, parm, *len);
 1936|  21.7k|			buflen += *len;
 1937|  21.7k|		} else {
 1938|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1939|      0|		}
 1940|  21.7k|		break;
 1941|  21.7k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      0|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1941:2): [True: 0, False: 32.7k]
  ------------------
 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|  4.50k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  4.50k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1954:2): [True: 4.50k, False: 28.2k]
  ------------------
 1955|  4.50k|		r = sc_asn1_encode_object_id(&buf, &buflen, (struct sc_object_id *) parm);
 1956|  4.50k|		break;
 1957|      0|	case SC_ASN1_PATH:
  ------------------
  |  |  174|      0|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1957:2): [True: 0, False: 32.7k]
  ------------------
 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: 32.7k]
  ------------------
 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: 32.7k]
  ------------------
 1974|      0|		r = asn1_encode_p15_object(ctx, (const struct sc_asn1_pkcs15_object *) parm, &buf, &buflen, depth);
 1975|      0|		break;
 1976|  1.63k|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|  1.63k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1976:2): [True: 1.63k, False: 31.0k]
  ------------------
 1977|  1.63k|		r = sc_asn1_encode_algorithm_id(ctx, &buf, &buflen, (const struct sc_algorithm_id *) parm, depth);
 1978|  1.63k|		break;
 1979|      0|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|      0|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1979:2): [True: 0, False: 32.7k]
  ------------------
 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: 32.7k]
  ------------------
 1985|      0|		r = callback_func(ctx, entry->arg, &buf, &buflen, depth);
 1986|      0|		break;
 1987|      0|	default:
  ------------------
  |  Branch (1987:2): [True: 0, False: 32.7k]
  ------------------
 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|  32.7k|	}
 1991|  32.7k|	if (r) {
  ------------------
  |  Branch (1991:6): [True: 15, False: 32.7k]
  ------------------
 1992|     15|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|     15|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1993|     15|		      sc_strerror(r));
 1994|     15|		if (buf)
  ------------------
  |  Branch (1994:7): [True: 0, False: 15]
  ------------------
 1995|      0|			free(buf);
 1996|     15|		return r;
 1997|     15|	}
 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|  49.7k|no_object:
 2010|  49.7k|	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  148|  67.6k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  17.8k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2010:6): [True: 17.8k, False: 31.9k]
  |  Branch (2010:17): [True: 17.8k, False: 4]
  |  Branch (2010:52): [True: 17.0k, False: 752]
  ------------------
 2011|       |		/* This happens when we try to encode e.g. the
 2012|       |		 * subClassAttributes, which may be empty */
 2013|  17.0k|		*obj = NULL;
 2014|  17.0k|		*objlen = 0;
 2015|  17.0k|		r = 0;
 2016|  32.7k|	} else if (!buflen && (entry->flags & SC_ASN1_EMPTY_ALLOWED)) {
  ------------------
  |  |  151|    756|#define SC_ASN1_EMPTY_ALLOWED           0x00000010
  ------------------
  |  Branch (2016:13): [True: 756, False: 31.9k]
  |  Branch (2016:24): [True: 0, False: 756]
  ------------------
 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|  32.7k|	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  158|  33.4k|#define SC_ASN1_NULL                    5
  ------------------
              	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  141|      4|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (2022:13): [True: 31.9k, False: 756]
  |  Branch (2022:23): [True: 752, False: 4]
  |  Branch (2022:54): [True: 0, False: 4]
  ------------------
 2023|  32.6k|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2024|  32.6k|		if (r)
  ------------------
  |  Branch (2024:7): [True: 0, False: 32.6k]
  ------------------
 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|  32.6k|					sc_strerror(r));
 2027|  32.6k|	} else if (!(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      4|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2027:13): [True: 0, False: 4]
  ------------------
 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|      4|	} else {
 2031|      4|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "cannot encode empty non-optional ASN.1 object\n");
  ------------------
  |  |   70|      4|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2032|      4|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      4|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2033|      4|	}
 2034|  49.7k|	if (buf)
  ------------------
  |  Branch (2034:6): [True: 31.9k, False: 17.8k]
  ------------------
 2035|  31.9k|		free(buf);
 2036|  49.7k|	if (r >= 0)
  ------------------
  |  Branch (2036:6): [True: 49.7k, False: 4]
  ------------------
 2037|  49.7k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|  49.7k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2038|  49.7k|			 "%*.*slength of encoded item=%"SC_FORMAT_LEN_SIZE_T"u\n",
 2039|  49.7k|			 depth, depth, "", *objlen);
 2040|  49.7k|	return r;
 2041|  32.7k|}
asn1.c:encode_bit_string:
  652|  1.63k|{
  653|  1.63k|	const u8 *in = inbuf;
  654|  1.63k|	u8 *out;
  655|  1.63k|	size_t bytes, skipped = 0;
  656|       |
  657|  1.63k|	bytes = BYTES4BITS(bits_left) + 1;
  ------------------
  |  |  146|  1.63k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  658|  1.63k|	*outbuf = out = malloc(bytes);
  659|  1.63k|	if (out == NULL)
  ------------------
  |  Branch (659:6): [True: 0, False: 1.63k]
  ------------------
  660|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  661|  1.63k|	*outlen = bytes;
  662|  1.63k|	out += 1;
  663|   108k|	while (bits_left) {
  ------------------
  |  Branch (663:9): [True: 107k, False: 1.63k]
  ------------------
  664|   107k|		size_t i, bits_to_go = 8;
  665|       |
  666|   107k|		*out = 0;
  667|   107k|		if (bits_left < 8) {
  ------------------
  |  Branch (667:7): [True: 0, False: 107k]
  ------------------
  668|      0|			bits_to_go = bits_left;
  669|      0|			skipped = 8 - bits_left;
  670|      0|		}
  671|   107k|		if (invert) {
  ------------------
  |  Branch (671:7): [True: 0, False: 107k]
  ------------------
  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|   107k|		} else {
  675|   107k|			*out = *in;
  676|   107k|			if (bits_left < 8)
  ------------------
  |  Branch (676:8): [True: 0, False: 107k]
  ------------------
  677|      0|				return SC_ERROR_NOT_SUPPORTED; /* FIXME */
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  678|   107k|		}
  679|   107k|		bits_left -= bits_to_go;
  680|   107k|		out++, in++;
  681|   107k|	}
  682|  1.63k|	out = *outbuf;
  683|  1.63k|	out[0] = skipped;
  684|  1.63k|	return 0;
  685|  1.63k|}

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

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

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

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

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

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

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

sc_get_cardos_driver:
 1570|  16.4k|{
 1571|  16.4k|	return sc_get_driver();
 1572|  16.4k|}
card-cardos.c:sc_get_driver:
 1545|  16.4k|{
 1546|  16.4k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1546:6): [True: 1, False: 16.4k]
  ------------------
 1547|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1548|  16.4k|	cardos_ops = *iso_ops;
 1549|  16.4k|	cardos_ops.match_card = cardos_match_card;
 1550|  16.4k|	cardos_ops.init = cardos_init;
 1551|  16.4k|	cardos_ops.finish = cardos_finish;
 1552|  16.4k|	cardos_ops.select_file = cardos_select_file;
 1553|  16.4k|	cardos_ops.create_file = cardos_create_file;
 1554|  16.4k|	cardos_ops.set_security_env = cardos_set_security_env;
 1555|  16.4k|	cardos_ops.restore_security_env = cardos_restore_security_env;
 1556|  16.4k|	cardos_ops.compute_signature = cardos_compute_signature;
 1557|  16.4k|	cardos_ops.decipher = cardos_decipher;
 1558|       |
 1559|  16.4k|	cardos_ops.list_files = cardos_list_files;
 1560|  16.4k|	cardos_ops.check_sw = cardos_check_sw;
 1561|  16.4k|	cardos_ops.card_ctl = cardos_card_ctl;
 1562|  16.4k|	cardos_ops.pin_cmd = cardos_pin_cmd;
 1563|  16.4k|	cardos_ops.logout  = cardos_logout;
 1564|       |
 1565|  16.4k|	return &cardos_drv;
 1566|  16.4k|}
card-cardos.c:cardos_match_card:
   76|  15.4k|{
   77|  15.4k|	unsigned char atr[SC_MAX_ATR_SIZE] = {0};
   78|  15.4k|	int i;
   79|       |
   80|  15.4k|	i = _sc_match_atr(card, cardos_atrs, &card->type);
   81|  15.4k|	if (i < 0)
  ------------------
  |  Branch (81:6): [True: 14.5k, False: 922]
  ------------------
   82|  14.5k|		return 0;
   83|       |
   84|    922|	memcpy(atr, card->atr.value, card->atr.len);
   85|       |
   86|       |	/* Do not change card type for CIE! */
   87|    922|	if (card->type == SC_CARD_TYPE_CARDOS_CIE_V1)
  ------------------
  |  Branch (87:6): [True: 0, False: 922]
  ------------------
   88|      0|		return 1;
   89|    922|	if (card->type == SC_CARD_TYPE_CARDOS_M4_4)
  ------------------
  |  Branch (89:6): [True: 0, False: 922]
  ------------------
   90|      0|		return 1;
   91|    922|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0)
  ------------------
  |  Branch (91:6): [True: 163, False: 759]
  ------------------
   92|    163|		return 1;
   93|    759|	if (card->type == SC_CARD_TYPE_CARDOS_V5_3)
  ------------------
  |  Branch (93:6): [True: 379, False: 380]
  ------------------
   94|    379|		return 1;
   95|    380|	if (card->type == SC_CARD_TYPE_CARDOS_M4_2) {
  ------------------
  |  Branch (95:6): [True: 364, False: 16]
  ------------------
   96|    364|		int rv;
   97|    364|		sc_apdu_t apdu = {0};
   98|    364|		u8 rbuf[SC_MAX_APDU_BUFFER_SIZE] = {0};
   99|       |		/* first check some additional ATR bytes */
  100|    364|		if ((atr[4] != 0xff && atr[4] != 0x02) ||
  ------------------
  |  Branch (100:8): [True: 13, False: 351]
  |  Branch (100:26): [True: 9, False: 4]
  ------------------
  101|    355|		    (atr[6] != 0x10 && atr[6] != 0x0a) ||
  ------------------
  |  Branch (101:8): [True: 350, False: 5]
  |  Branch (101:26): [True: 10, False: 340]
  ------------------
  102|    345|		    (atr[9] != 0x55 && atr[9] != 0x58))
  ------------------
  |  Branch (102:8): [True: 344, False: 1]
  |  Branch (102:26): [True: 15, False: 329]
  ------------------
  103|     34|			return 0;
  104|       |		/* get the os version using GET DATA and compare it with
  105|       |		 * version in the ATR */
  106|    330|		sc_log(card->ctx,  "checking cardos version ...");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  107|    330|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x82);
  ------------------
  |  |  292|    330|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  108|    330|		apdu.resp = rbuf;
  109|    330|		apdu.resplen = sizeof(rbuf);
  110|    330|		apdu.le = 256;
  111|    330|		apdu.lc = 0;
  112|    330|		rv = sc_transmit_apdu(card, &apdu);
  113|    330|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  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: 3, False: 327]
  |  |  |  |  ------------------
  |  |  |  |  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|    330|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 327]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  114|    327|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00 || apdu.resplen < 2)
  ------------------
  |  Branch (114:7): [True: 279, False: 48]
  |  Branch (114:27): [True: 2, False: 46]
  |  Branch (114:47): [True: 2, False: 44]
  ------------------
  115|    283|			return 0;
  116|     44|		if (apdu.resp[0] != atr[10] ||
  ------------------
  |  Branch (116:7): [True: 7, False: 37]
  ------------------
  117|     37|		    apdu.resp[1] != atr[11])
  ------------------
  |  Branch (117:7): [True: 6, False: 31]
  ------------------
  118|       |			/* version mismatch */
  119|     13|			return 0;
  120|     31|		if (atr[11] <= 0x04) {
  ------------------
  |  Branch (120:7): [True: 3, False: 28]
  ------------------
  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|     28|		} else if (atr[11] == 0x08) {
  ------------------
  |  Branch (123:14): [True: 1, False: 27]
  ------------------
  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|     27|		} else if (atr[11] == 0x09) {
  ------------------
  |  Branch (126:14): [True: 1, False: 26]
  ------------------
  127|      1|			sc_log(card->ctx,  "found cardos v4.2b");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  128|      1|			card->type = SC_CARD_TYPE_CARDOS_M4_2B;
  129|     26|		} else if (atr[11] >= 0x0B) {
  ------------------
  |  Branch (129:14): [True: 9, False: 17]
  ------------------
  130|      9|			sc_log(card->ctx,  "found cardos v4.2c or higher");
  ------------------
  |  |   71|      9|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  131|      9|			card->type = SC_CARD_TYPE_CARDOS_M4_2C;
  132|     17|		} else {
  133|     17|			sc_log(card->ctx,  "found cardos m4.2");
  ------------------
  |  |   71|     17|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  134|     17|		}
  135|     31|	}
  136|     47|	return 1;
  137|    380|}
card-cardos.c:cardos_init:
  212|    589|{
  213|    589|	cardos_data_t * priv = NULL;
  214|    589|	unsigned long flags = 0;
  215|    589|	size_t data_field_length;
  216|    589|	sc_apdu_t apdu;
  217|    589|	u8 rbuf[2];
  218|    589|	int r;
  219|       |
  220|    589|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    589|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    589|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    589|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 589]
  |  |  ------------------
  ------------------
  221|       |
  222|    589|	priv = calloc(1, sizeof(cardos_data_t));
  223|    589|	if (!priv)
  ------------------
  |  Branch (223:6): [True: 0, False: 589]
  ------------------
  224|    589|		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|    589|	card->drv_data = priv;
  226|       |
  227|    589|	card->name = "Atos CardOS";
  228|    589|	card->cla = 0x00;
  229|       |
  230|       |	/* let user override flags and type from opensc.conf */
  231|       |	/* user can override card->type too.*/
  232|    589|	if (card->flags) {
  ------------------
  |  Branch (232:6): [True: 0, False: 589]
  ------------------
  233|      0|	    flags = card->flags;
  234|    589|	} else {
  235|       |
  236|       |		/* Set up algorithm info. */
  237|    589|		flags = 0;
  238|    589|		if (card->type == SC_CARD_TYPE_CARDOS_V5_0) {
  ------------------
  |  Branch (238:7): [True: 163, False: 426]
  ------------------
  239|    163|			flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|    163|#define SC_ALGORITHM_RSA_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|    163|#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|    163|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  240|    426|		} else if(card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (240:13): [True: 379, False: 47]
  ------------------
  241|    379|			flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  111|    379|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  242|    379|				| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  142|    379|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|    379|				| SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    379|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  244|    379|		} else {
  245|     47|			flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  111|     47|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  246|     47|				| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  142|     47|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  247|     47|				| SC_ALGORITHM_NEED_USAGE
  ------------------
  |  |  104|     47|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  248|     47|				| SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     47|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  249|     47|		}
  250|    589|	}
  251|       |
  252|    589|	priv->flags = flags;
  253|       |
  254|    589|	if (card->type == SC_CARD_TYPE_CARDOS_M4_2) {
  ------------------
  |  Branch (254:6): [True: 17, False: 572]
  ------------------
  255|     17|		r = cardos_have_2048bit_package(card);
  256|     17|		if (r < 0) {
  ------------------
  |  Branch (256:7): [True: 2, False: 15]
  ------------------
  257|      2|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      2|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  258|      2|			goto err;
  259|      2|		}
  260|     15|		if (r == 1)
  ------------------
  |  Branch (260:7): [True: 1, False: 14]
  ------------------
  261|      1|			priv->rsa_2048 = 1;
  262|     15|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|     15|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  263|    572|	} else if (card->type == SC_CARD_TYPE_CARDOS_M4_3
  ------------------
  |  Branch (263:13): [True: 1, False: 571]
  ------------------
  264|    571|		|| card->type == SC_CARD_TYPE_CARDOS_M4_2B
  ------------------
  |  Branch (264:6): [True: 1, False: 570]
  ------------------
  265|    570|		|| card->type == SC_CARD_TYPE_CARDOS_M4_2C
  ------------------
  |  Branch (265:6): [True: 9, False: 561]
  ------------------
  266|    561|		|| card->type == SC_CARD_TYPE_CARDOS_M4_4
  ------------------
  |  Branch (266:6): [True: 0, False: 561]
  ------------------
  267|    561|		|| card->type == SC_CARD_TYPE_CARDOS_V5_0
  ------------------
  |  Branch (267:6): [True: 163, False: 398]
  ------------------
  268|    553|		|| card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (268:6): [True: 379, False: 19]
  ------------------
  269|    553|		priv->rsa_2048 = 1;
  270|    553|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|    553|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  271|       |		/* TODO check this. EC only if in supported_algo */
  272|    553|		priv->ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|    553|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		priv->ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|    553|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  273|    553|	}
  274|       |
  275|       |	/* probe DATA FIELD LENGTH with GET DATA */
  276|    587|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x8D);
  ------------------
  |  |  292|    587|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  277|    587|	apdu.le = sizeof rbuf;
  278|    587|	apdu.resp = rbuf;
  279|    587|	apdu.resplen = sizeof(rbuf);
  280|       |
  281|    587|	r = sc_transmit_apdu(card, &apdu);
  282|    587|	if (r < 0)
  ------------------
  |  Branch (282:6): [True: 3, False: 584]
  ------------------
  283|    587|		LOG_TEST_GOTO_ERR(card->ctx,
  ------------------
  |  |  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: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  284|    584|				SC_ERROR_INVALID_CARD,
  285|    584|				"APDU transmit failed");
  286|    584|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  287|    584|	if (r < 0)
  ------------------
  |  Branch (287:6): [True: 112, False: 472]
  ------------------
  288|    584|		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|    472|				SC_ERROR_INVALID_CARD,
  290|    472|				"GET DATA command returned error");
  291|    472|	if (apdu.resplen != 2) {
  ------------------
  |  Branch (291:6): [True: 8, False: 464]
  ------------------
  292|      8|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      8|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  293|      8|		goto err;
  294|      8|	}
  295|    464|	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|    464|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (301:6): [True: 156, False: 308]
  |  Branch (301:48): [True: 287, False: 21]
  ------------------
  302|    443|		sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "data_field_length:%"SC_FORMAT_LEN_SIZE_T"u "
  ------------------
  |  |   70|    443|#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|    443|				data_field_length, card->reader->max_send_size, card->reader->max_recv_size,
  |  |  |  |  306|    443|				(card->caps & SC_CARD_CAP_APDU_EXT) ? "SC_CARD_CAP_APDU_EXT" : " ");
  |  |  |  |  ------------------
  |  |  |  |  |  |  554|    443|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|    443|				"card->reader->max_send_size:%"SC_FORMAT_LEN_SIZE_T"u "
  304|    443|				"card->reader->max_recv_size:%"SC_FORMAT_LEN_SIZE_T"u %s",
  305|    443|				data_field_length, card->reader->max_send_size, card->reader->max_recv_size,
  306|    443|				(card->caps & SC_CARD_CAP_APDU_EXT) ? "SC_CARD_CAP_APDU_EXT" : " ");
  307|       |
  308|    443|		if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  554|    443|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (308:7): [True: 443, False: 0]
  ------------------
  309|    443|			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|    443|		} else
  323|      0|			card->max_send_size = data_field_length - 3;
  324|       |
  325|    443|		card->max_send_size = sc_get_max_send_size(card); /* include reader sizes and protocol */
  326|    443|		card->max_recv_size = data_field_length - 2;
  327|    443|		card->max_recv_size = sc_get_max_recv_size(card);
  328|    443|	} else {
  329|       |		/* old way, disregards reader capabilities */
  330|     21|		if (card->caps & SC_CARD_CAP_APDU_EXT)
  ------------------
  |  |  554|     21|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (330:7): [True: 5, False: 16]
  ------------------
  331|      5|			card->max_send_size = data_field_length - 6;
  332|     16|		else
  333|     16|			card->max_send_size = data_field_length - 3;
  334|       |		/* strip the length of SW bytes */
  335|     21|		card->max_recv_size = data_field_length - 2;
  336|     21|	}
  337|       |
  338|       |	/*for new cards, wait till after sc_pkcs15_bind_internal reads tokeninfo */
  339|    464|	if (card->type != SC_CARD_TYPE_CARDOS_V5_0 && card->type != SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (339:6): [True: 308, False: 156]
  |  Branch (339:48): [True: 21, False: 287]
  ------------------
  340|     21|		r = cardos_add_algs(card, flags, 0, 0);
  341|     21|	}
  342|       |
  343|    589|err:
  344|    589|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    589|#define SC_SUCCESS				0
  ------------------
  |  Branch (344:6): [True: 125, False: 464]
  ------------------
  345|    125|		free(priv);
  346|    125|		card->drv_data = NULL;
  347|    125|	}
  348|       |
  349|    589|	return r;
  350|    464|}
card-cardos.c:cardos_have_2048bit_package:
  140|     17|{
  141|     17|	sc_apdu_t apdu;
  142|     17|        u8        rbuf[SC_MAX_APDU_BUFFER_SIZE];
  143|     17|        int       r;
  144|     17|	const u8  *p = rbuf, *q, *pp;
  145|     17|	size_t    len, tlen = 0, ilen = 0;
  146|       |
  147|     17|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x88);
  ------------------
  |  |  292|     17|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  148|     17|	apdu.resp    = rbuf;
  149|     17|	apdu.resplen = sizeof(rbuf);
  150|     17|	apdu.lc = 0;
  151|     17|	apdu.le = 256;
  152|     17|	r = sc_transmit_apdu(card, &apdu);
  153|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  154|       |
  155|     15|	if ((len = apdu.resplen) == 0)
  ------------------
  |  Branch (155:6): [True: 3, False: 12]
  ------------------
  156|       |		/* looks like no package has been installed  */
  157|      3|		return 0;
  158|       |
  159|     79|	while (len != 0) {
  ------------------
  |  Branch (159:9): [True: 72, False: 7]
  ------------------
  160|     72|		pp = sc_asn1_find_tag(card->ctx, p, len, 0xe1, &tlen);
  161|     72|		if (pp == NULL)
  ------------------
  |  Branch (161:7): [True: 2, False: 70]
  ------------------
  162|      2|			return 0;
  163|     70|		q = sc_asn1_find_tag(card->ctx, pp, tlen, 0x01, &ilen);
  164|     70|		if (q == NULL || ilen != 4)
  ------------------
  |  Branch (164:7): [True: 1, False: 69]
  |  Branch (164:20): [True: 1, False: 68]
  ------------------
  165|      2|			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|      7|	return 0;
  173|     12|}
card-cardos.c:cardos_add_algs:
  179|     30|{
  180|       |
  181|     30|	cardos_data_t * priv = (cardos_data_t *)card->drv_data;
  182|       |
  183|     30|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     30|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     30|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     30|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 30]
  |  |  ------------------
  ------------------
  184|       |
  185|     30|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  186|     30|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  187|     30|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  188|     30|	if (priv->rsa_2048 == 1) {
  ------------------
  |  Branch (188:6): [True: 13, False: 17]
  ------------------
  189|     13|		_sc_card_add_rsa_alg(card, 1280, flags, 0);
  190|     13|		_sc_card_add_rsa_alg(card, 1536, flags, 0);
  191|     13|		_sc_card_add_rsa_alg(card, 1792, flags, 0);
  192|     13|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  193|     13|	}
  194|       |
  195|     30|	if (card->type == SC_CARD_TYPE_CARDOS_V5_0 || card->type == SC_CARD_TYPE_CARDOS_V5_3) {
  ------------------
  |  Branch (195:6): [True: 6, False: 24]
  |  Branch (195:48): [True: 3, False: 21]
  ------------------
  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|     30|	if (ec_flags != 0) {
  ------------------
  |  Branch (203:6): [True: 0, False: 30]
  ------------------
  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|     30|	return 0;
  209|     30|}
card-cardos.c:cardos_finish:
  377|    464|{
  378|    464|	int r = 0;
  379|       |
  380|    464|	if (card == NULL )
  ------------------
  |  Branch (380:6): [True: 0, False: 464]
  ------------------
  381|      0|		return 0;
  382|       |
  383|    464|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    464|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    464|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    464|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 464]
  |  |  ------------------
  ------------------
  384|       |
  385|       |	/* free priv data */
  386|    464|	if (card->drv_data) { /* priv */
  ------------------
  |  Branch (386:6): [True: 464, False: 0]
  ------------------
  387|    464|		free(card->drv_data);
  388|    464|		card->drv_data = NULL;
  389|    464|	}
  390|       |
  391|    464|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    464|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    464|	int _ret = r; \
  |  |  155|    464|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 464, False: 0]
  |  |  ------------------
  |  |  156|    464|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 464]
  |  |  ------------------
  |  |  157|    464|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    464|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    464|	return _ret; \
  |  |  163|    464|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  392|    464|}
card-cardos.c:cardos_select_file:
  634|  3.04k|{
  635|  3.04k|	int r;
  636|       |
  637|  3.04k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.04k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.04k]
  |  |  ------------------
  ------------------
  638|  3.04k|	r = iso_ops->select_file(card, in_path, file);
  639|  3.04k|	if (r >= 0 && file)
  ------------------
  |  Branch (639:6): [True: 642, False: 2.40k]
  |  Branch (639:16): [True: 410, False: 232]
  ------------------
  640|    410|		parse_sec_attr((*file), (*file)->sec_attr, (*file)->sec_attr_len);
  641|  3.04k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.04k|	int _ret = r; \
  |  |  |  |  155|  3.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  2.40k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.40k, False: 642]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.04k|	return _ret; \
  |  |  |  |  163|  3.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  642|  3.04k|}
card-cardos.c:parse_sec_attr:
  619|    410|{
  620|    410|	size_t i;
  621|    410|	const int *idx;
  622|       |
  623|    410|	idx = (file->type == SC_FILE_TYPE_DF) ?  df_acl : ef_acl;
  ------------------
  |  |  214|    410|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (623:8): [True: 4, False: 406]
  ------------------
  624|       |
  625|       |	/* acl defaults to 0xFF if unspecified */
  626|  4.10k|	for (i = 0; i < 9; i++)
  ------------------
  |  Branch (626:14): [True: 3.69k, False: 410]
  ------------------
  627|  3.69k|		if (idx[i] != -1)
  ------------------
  |  Branch (627:7): [True: 2.86k, False: 824]
  ------------------
  628|  2.86k|			add_acl_entry(file, idx[i], (u8)((i < len) ? buf[i] : 0xFF));
  ------------------
  |  Branch (628:37): [True: 220, False: 2.64k]
  ------------------
  629|    410|}
card-cardos.c:add_acl_entry:
  546|  2.86k|{
  547|  2.86k|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  2.86k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  548|       |
  549|  2.86k|	switch (byte) {
  550|     37|	case 0x00:
  ------------------
  |  Branch (550:2): [True: 37, False: 2.82k]
  ------------------
  551|     37|		method = SC_AC_NONE;
  ------------------
  |  |  150|     37|#define SC_AC_NONE			0x00000000
  ------------------
  552|     37|		break;
  553|  2.67k|	case 0xFF:
  ------------------
  |  Branch (553:2): [True: 2.67k, False: 187]
  ------------------
  554|  2.67k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  2.67k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  555|  2.67k|		break;
  556|    150|	default:
  ------------------
  |  Branch (556:2): [True: 150, False: 2.71k]
  ------------------
  557|    150|		if (byte > 0x7F) {
  ------------------
  |  Branch (557:7): [True: 60, False: 90]
  ------------------
  558|     60|			method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     60|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  559|     90|		} else {
  560|     90|			method = SC_AC_CHV;
  ------------------
  |  |  151|     90|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  561|     90|			key_ref = byte;
  562|     90|		}
  563|    150|		break;
  564|  2.86k|	}
  565|  2.86k|	sc_file_add_acl_entry(file, op, method, key_ref);
  566|  2.86k|}
card-cardos.c:cardos_check_sw:
  458|  6.70k|{
  459|  6.70k|	const int err_count = sizeof(cardos_errors)/sizeof(cardos_errors[0]);
  460|  6.70k|	int i;
  461|       |
  462|   162k|	for (i = 0; i < err_count; i++) {
  ------------------
  |  Branch (462:14): [True: 162k, False: 259]
  ------------------
  463|   162k|		if (cardos_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (463:7): [True: 6.44k, False: 155k]
  ------------------
  464|  6.44k|			if ( cardos_errors[i].errorstr )
  ------------------
  |  Branch (464:9): [True: 2.96k, False: 3.48k]
  ------------------
  465|  2.96k|				sc_log(card->ctx,  "%s\n",
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  466|  6.44k|				 	cardos_errors[i].errorstr);
  467|  6.44k|			return cardos_errors[i].errorno;
  468|  6.44k|		}
  469|   162k|	}
  470|       |
  471|    259|        sc_log(card->ctx,  "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
  ------------------
  |  |   71|    259|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  472|    259|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    259|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  473|  6.70k|}
card-cardos.c:cardos_card_ctl:
 1447|     44|{
 1448|     44|	switch (cmd) {
  ------------------
  |  Branch (1448:10): [True: 44, False: 0]
  ------------------
 1449|      0|	case SC_CARDCTL_CARDOS_PUT_DATA_FCI:
  ------------------
  |  Branch (1449:2): [True: 0, False: 44]
  ------------------
 1450|      0|		break;
 1451|      0|	case SC_CARDCTL_CARDOS_PUT_DATA_OCI:
  ------------------
  |  Branch (1451:2): [True: 0, False: 44]
  ------------------
 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: 44]
  ------------------
 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: 44]
  ------------------
 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: 26]
  ------------------
 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: 44]
  ------------------
 1466|      0|		return cardos_lifecycle_get(card, (int *) ptr);
 1467|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1467:2): [True: 0, False: 44]
  ------------------
 1468|      0|		return cardos_lifecycle_set(card, (int *) ptr);
 1469|     26|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1469:2): [True: 26, False: 18]
  ------------------
 1470|     26|		return cardos_get_serialnr(card, (sc_serial_number_t *)ptr);
 1471|     44|	}
 1472|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1473|     44|}
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|     26|{
 1415|     26|	int r;
 1416|     26|	sc_apdu_t apdu;
 1417|     26|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1418|       |
 1419|     26|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x81);
  ------------------
  |  |  292|     26|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1420|     26|	apdu.resp = rbuf;
 1421|     26|	apdu.resplen = sizeof(rbuf);
 1422|     26|	apdu.le   = 256;
 1423|     26|	r = sc_transmit_apdu(card, &apdu);
 1424|     26|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|     26|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     26|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     26|	int _ret = (r); \
  |  |  |  |  168|     26|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1425|     22|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1425:6): [True: 12, False: 10]
  |  Branch (1425:26): [True: 3, False: 7]
  ------------------
 1426|     15|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     15|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1427|      7|	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: 4]
  |  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|      5|	} else if (apdu.resplen == 32) {
  ------------------
  |  Branch (1431:13): [True: 1, False: 4]
  ------------------
 1432|       |		/* cache serial number */
 1433|      1|		memcpy(card->serialnr.value, &rbuf[10], 6);
 1434|      1|		card->serialnr.len = 6;
 1435|      4|	} else {
 1436|      4|		sc_log(card->ctx,  "unexpected response to GET DATA serial"
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1437|      4|				" number\n");
 1438|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1439|      4|	}
 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|      7|}
card-cardos.c:cardos_pin_cmd:
 1482|     25|{
 1483|     25|	struct sc_context *ctx = card->ctx;
 1484|     25|	int rv;
 1485|       |
 1486|     25|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1487|       |
 1488|     25|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|     25|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1489|     25|	data->pin_reference |= 0x80;
 1490|       |
 1491|     25|	sc_log(ctx, "PIN_CMD(cmd:%i, ref:%i)", data->cmd, data->pin_reference);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1492|     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__
  |  |  ------------------
  ------------------
 1493|     25|	       "PIN1(max:%"SC_FORMAT_LEN_SIZE_T"u, min:%"SC_FORMAT_LEN_SIZE_T"u)",
 1494|     25|	       data->pin1.max_length, data->pin1.min_length);
 1495|     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__
  |  |  ------------------
  ------------------
 1496|     25|	       "PIN2(max:%"SC_FORMAT_LEN_SIZE_T"u, min:%"SC_FORMAT_LEN_SIZE_T"u)",
 1497|     25|	       data->pin2.max_length, data->pin2.min_length);
 1498|       |
 1499|       |	/* FIXME: the following values depend on what pin length was
 1500|       |	 * used when creating the BS objects */
 1501|     25|	if (data->pin1.max_length == 0)
  ------------------
  |  Branch (1501:6): [True: 25, False: 0]
  ------------------
 1502|     25|		data->pin1.max_length = 8;
 1503|     25|	if (data->pin2.max_length == 0)
  ------------------
  |  Branch (1503:6): [True: 25, False: 0]
  ------------------
 1504|     25|		data->pin2.max_length = 8;
 1505|       |
 1506|     25|	rv = iso_ops->pin_cmd(card, data);
 1507|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1508|     25|}

coolkey_get_attribute_data:
  602|  2.70k|{
  603|       |	/* handle the V0 objects first */
  604|  2.70k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  2.70k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (604:6): [True: 130, False: 2.57k]
  ------------------
  605|    130|		return coolkey_v0_get_attribute_data(attr, buf_len, attr_out);
  606|    130|	}
  607|       |
  608|       |	/* don't crash if we encounter some new or corrupted coolkey device */
  609|  2.57k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  2.57k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (609:6): [True: 0, False: 2.57k]
  ------------------
  610|      0|		return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  611|      0|	}
  612|       |
  613|  2.57k|	return coolkey_v1_get_attribute_data(attr, buf_len, attr_out);
  614|       |
  615|  2.57k|}
coolkey_compare_id:
  757|   240k|{
  758|   240k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (758:6): [True: 0, False: 240k]
  |  Branch (758:19): [True: 0, False: 240k]
  ------------------
  759|      0|		return 1;
  760|   240k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  761|   240k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  762|   240k|}
coolkey_list_meter:
  765|  8.61k|size_t coolkey_list_meter(const void *el) {
  766|  8.61k|	return sizeof(sc_cardctl_coolkey_object_t);
  767|  8.61k|}
coolkey_fill_object:
 1372|  35.0k|{
 1373|  35.0k|	int r;
 1374|  35.0k|	size_t buf_len = obj->length;
 1375|  35.0k|	u8 *new_obj_data = NULL;
 1376|  35.0k|	sc_cardctl_coolkey_object_t *obj_entry;
 1377|  35.0k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  35.0k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1378|       |
 1379|  35.0k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  35.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  35.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  35.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  35.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 35.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1380|       |
 1381|  35.0k|	if (obj->data != NULL) {
  ------------------
  |  Branch (1381:6): [True: 0, False: 35.0k]
  ------------------
 1382|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1383|      0|	}
 1384|  35.0k|	new_obj_data = malloc(buf_len);
 1385|  35.0k|	if (new_obj_data == NULL) {
  ------------------
  |  Branch (1385:6): [True: 0, False: 35.0k]
  ------------------
 1386|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1387|      0|	}
 1388|  35.0k|	r = coolkey_read_object(card, obj->id, 0, new_obj_data, buf_len,
 1389|  35.0k|				priv->nonce, sizeof(priv->nonce));
 1390|  35.0k|	if (r != (int)buf_len) {
  ------------------
  |  Branch (1390:6): [True: 32.7k, False: 2.34k]
  ------------------
 1391|  32.7k|		free(new_obj_data);
 1392|  32.7k|		if (r < 0) {
  ------------------
  |  Branch (1392:7): [True: 32.7k, False: 0]
  ------------------
 1393|  32.7k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  32.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  32.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  32.7k|	int _ret = r; \
  |  |  |  |  155|  32.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  32.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|  32.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  32.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  32.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|  32.7k|	return _ret; \
  |  |  |  |  163|  32.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1394|  32.7k|		}
 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.34k|	obj_entry = coolkey_find_object_by_id(&priv->objects_list, obj->id);
 1398|  2.34k|	if (obj_entry == NULL) {
  ------------------
  |  Branch (1398:6): [True: 0, False: 2.34k]
  ------------------
 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.34k|	if (obj_entry->data != NULL) {
  ------------------
  |  Branch (1402:6): [True: 0, False: 2.34k]
  ------------------
 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.34k|	if (obj_entry->length != obj->length) {
  ------------------
  |  Branch (1408:6): [True: 0, False: 2.34k]
  ------------------
 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.34k|	obj_entry->data = new_obj_data;
 1413|  2.34k|	obj->data = new_obj_data;
 1414|  2.34k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.34k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.34k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.34k|	int _ret = r; \
  |  |  |  |  155|  2.34k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.34k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.34k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.34k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.34k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.34k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.34k|	return _ret; \
  |  |  |  |  163|  2.34k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1415|  2.34k|}
coolkey_find_object_by_template:
 1504|  1.63k|{
 1505|  1.63k|	list_t *list;
 1506|  1.63k|	sc_cardctl_coolkey_object_t *current, *rv = NULL;
 1507|  1.63k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.63k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1508|  1.63k|	int i, r;
 1509|  1.63k|	unsigned int tmp_pos = (unsigned int) -1;
 1510|       |
 1511|  1.63k|	list = &priv->objects_list;
 1512|  1.63k|	if (list->iter_active) {
  ------------------
  |  Branch (1512:6): [True: 1.63k, False: 0]
  ------------------
 1513|       |		/* workaround missing functionality of second iterator */
 1514|  1.63k|		tmp_pos = list->iter_pos;
 1515|  1.63k|		list_iterator_stop(list);
 1516|  1.63k|	}
 1517|       |
 1518|  1.63k|	list_iterator_start(list);
 1519|  27.5k|	while (list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1519:9): [True: 26.9k, False: 667]
  ------------------
 1520|  26.9k|		sc_cardctl_coolkey_attribute_t attribute;
 1521|  26.9k|		current = list_iterator_next(list);
 1522|  26.9k|		attribute.object = current;
 1523|       |
 1524|  30.6k|		for (i=0; i < count; i++) {
  ------------------
  |  Branch (1524:13): [True: 29.6k, False: 972]
  ------------------
 1525|  29.6k|			attribute.attribute_type = template[i].attribute_type;
 1526|  29.6k|			r = coolkey_find_attribute(card, &attribute);
 1527|  29.6k|			if (r < 0) {
  ------------------
  |  Branch (1527:8): [True: 18.5k, False: 11.0k]
  ------------------
 1528|  18.5k|				break;
 1529|  18.5k|			}
 1530|  11.0k|			if (template[i].attribute_data_type != attribute.attribute_data_type) {
  ------------------
  |  Branch (1530:8): [True: 147, False: 10.9k]
  ------------------
 1531|    147|				break;
 1532|    147|			}
 1533|  10.9k|			if (template[i].attribute_length != attribute.attribute_length) {
  ------------------
  |  Branch (1533:8): [True: 122, False: 10.8k]
  ------------------
 1534|    122|				break;
 1535|    122|			}
 1536|  10.8k|			if (memcmp(attribute.attribute_value, template[i].attribute_value,
  ------------------
  |  Branch (1536:8): [True: 7.10k, False: 3.71k]
  ------------------
 1537|  10.8k|							attribute.attribute_length) != 0) {
 1538|  7.10k|				break;
 1539|  7.10k|			}
 1540|  10.8k|		}
 1541|       |		/* just return the first one */
 1542|  26.9k|		if (i == count) {
  ------------------
  |  Branch (1542:7): [True: 972, False: 25.9k]
  ------------------
 1543|    972|			rv = current;
 1544|    972|			break;
 1545|    972|		}
 1546|  26.9k|	}
 1547|       |
 1548|  1.63k|	list_iterator_stop(list);
 1549|  1.63k|	if (tmp_pos != (unsigned int)-1) {
  ------------------
  |  Branch (1549:6): [True: 1.63k, False: 0]
  ------------------
 1550|       |		/* workaround missing functionality of second iterator */
 1551|  1.63k|		list_iterator_start(list);
 1552|  20.0k|		while (list_iterator_hasnext(list) && list->iter_pos < tmp_pos)
  ------------------
  |  Branch (1552:10): [True: 19.8k, False: 140]
  |  Branch (1552:41): [True: 18.3k, False: 1.49k]
  ------------------
 1553|  18.3k|			(void) list_iterator_next(list);
 1554|  1.63k|	}
 1555|  1.63k|	return rv;
 1556|  1.63k|}
sc_get_coolkey_driver:
 2476|  16.4k|{
 2477|  16.4k|	return sc_get_driver();
 2478|  16.4k|}
card-coolkey.c:coolkey_v0_get_attribute_data:
  517|    130|{
  518|       |	/* we need to manually detect types CK_ULONG */
  519|    130|	CK_ATTRIBUTE_TYPE attr_type = coolkey_get_attribute_type(attr, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|    130|#define COOLKEY_V0_OBJECT 0
  ------------------
  520|    130|	int r;
  521|    130|	size_t len;
  522|       |
  523|    130|	attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1048|    130|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
  524|    130|	attr_out->attribute_length = 0;
  525|    130|	attr_out->attribute_value = NULL;
  526|       |
  527|    130|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  528|    130|	if (r < 0) {
  ------------------
  |  Branch (528:6): [True: 0, False: 130]
  ------------------
  529|      0|		return r;
  530|      0|	}
  531|    130|	if (len + sizeof(coolkey_v0_attribute_header_t) > buf_len) {
  ------------------
  |  Branch (531:6): [True: 29, False: 101]
  ------------------
  532|     29|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     29|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  533|     29|	}
  534|    101|	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  137|    101|#define CKA_CLASS 0x00000000UL
  ------------------
              	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  145|     20|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (534:6): [True: 81, False: 20]
  |  Branch (534:34): [True: 0, False: 20]
  ------------------
  535|     83|									 || (attr_type == CKA_KEY_TYPE)) {
  ------------------
  |  |  159|     20|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (535:14): [True: 2, False: 18]
  ------------------
  536|     83|		if (len != 4) {
  ------------------
  |  Branch (536:7): [True: 34, False: 49]
  ------------------
  537|     34|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     34|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  538|     34|		}
  539|     49|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|     49|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  540|     49|	}
  541|       |	/* return the length and the data */
  542|     67|	attr_out->attribute_length = len;
  543|     67|	attr_out->attribute_value = attr + sizeof(coolkey_v0_attribute_header_t);
  544|     67|	return SC_SUCCESS;
  ------------------
  |  |   28|     67|#define SC_SUCCESS				0
  ------------------
  545|    101|}
card-coolkey.c:coolkey_get_attribute_type:
  410|  27.6k|{
  411|  27.6k|	coolkey_attribute_header_t *attribute_header = (coolkey_attribute_header_t *) attr;
  412|       |
  413|  27.6k|	return bebytes2ulong(attribute_header->attribute_attr_type);
  414|  27.6k|}
card-coolkey.c:coolkey_v0_get_attribute_len:
  350|  2.98k|{
  351|  2.98k|	coolkey_v0_attribute_header_t *attribute_head = (coolkey_v0_attribute_header_t *)attr;
  352|       |	/* don't reference beyond our buffer */
  353|  2.98k|	if (buf_len < sizeof(coolkey_v0_attribute_header_t)) {
  ------------------
  |  Branch (353:6): [True: 98, False: 2.88k]
  ------------------
  354|     98|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     98|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  355|     98|	}
  356|  2.88k|	*len = bebytes2ushort(attribute_head->attribute_data_len);
  357|  2.88k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.88k|#define SC_SUCCESS				0
  ------------------
  358|  2.98k|}
card-coolkey.c:coolkey_v1_get_attribute_data:
  552|  2.57k|{
  553|  2.57k|	int r;
  554|  2.57k|	size_t len;
  555|  2.57k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  556|       |
  557|  2.57k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (557:6): [True: 36, False: 2.54k]
  ------------------
  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.54k|	switch (attribute_head->attribute_data_type) {
  563|       |	/* ULONG has implied length of 4 */
  564|    184|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|    184|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (564:2): [True: 184, False: 2.35k]
  ------------------
  565|    184|		if (buf_len < (sizeof(coolkey_attribute_header_t) + 4)) {
  ------------------
  |  Branch (565:7): [True: 19, False: 165]
  ------------------
  566|     19|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     19|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  567|     19|		}
  568|    165|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|    165|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  569|    165|		attr_out->attribute_length = 4;
  570|    165|		attr_out->attribute_value = attr + sizeof(coolkey_attribute_header_t);
  571|    165|		return SC_SUCCESS;
  ------------------
  |  |   28|    165|#define SC_SUCCESS				0
  ------------------
  572|       |	/* BOOL_FALSE and BOOL_TRUE have implied length and data */
  573|       |	/* return type STRING for BOOLS */
  574|     55|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|     55|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (574:2): [True: 55, False: 2.48k]
  ------------------
  575|     55|		attr_out->attribute_length = 1;
  576|     55|		attr_out->attribute_value =  &coolkey_static_false;
  577|     55|		return SC_SUCCESS;
  ------------------
  |  |   28|     55|#define SC_SUCCESS				0
  ------------------
  578|     94|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|     94|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (578:2): [True: 94, False: 2.44k]
  ------------------
  579|     94|		attr_out->attribute_length = 1;
  580|     94|		attr_out->attribute_value =  &coolkey_static_true;
  581|     94|		return SC_SUCCESS;
  ------------------
  |  |   28|     94|#define SC_SUCCESS				0
  ------------------
  582|       |	/* string type has encoded length */
  583|  1.65k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|  1.65k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (583:2): [True: 1.65k, False: 889]
  ------------------
  584|  1.65k|		r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 0);
  585|  1.65k|		if (r < SC_SUCCESS) {
  ------------------
  |  |   28|  1.65k|#define SC_SUCCESS				0
  ------------------
  |  Branch (585:7): [True: 36, False: 1.61k]
  ------------------
  586|     36|			return r;
  587|     36|		}
  588|  1.61k|		if (buf_len < (len + sizeof(coolkey_attribute_header_t) + 2)) {
  ------------------
  |  Branch (588:7): [True: 105, False: 1.51k]
  ------------------
  589|    105|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    105|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  590|    105|		}
  591|  1.51k|		attr_out->attribute_value = attr+sizeof(coolkey_attribute_header_t)+2;
  592|  1.51k|		attr_out->attribute_length = len;
  593|  1.51k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.51k|#define SC_SUCCESS				0
  ------------------
  594|    556|	default:
  ------------------
  |  Branch (594:2): [True: 556, False: 1.98k]
  ------------------
  595|    556|		break;
  596|  2.54k|	}
  597|    556|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    556|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  598|  2.54k|}
card-coolkey.c:coolkey_v1_get_attribute_len:
  313|   142k|{
  314|   142k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  315|       |
  316|   142k|	*len = 0;
  317|       |	/* don't reference beyond our buffer */
  318|   142k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (318:6): [True: 113k, False: 28.6k]
  ------------------
  319|   113k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|   113k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  320|   113k|	}
  321|  28.6k|	switch (attribute_head->attribute_data_type) {
  322|  16.8k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|  16.8k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (322:2): [True: 16.8k, False: 11.8k]
  ------------------
  323|  16.8k|		if (buf_len < (sizeof(coolkey_attribute_header_t) +2)) {
  ------------------
  |  Branch (323:7): [True: 369, False: 16.4k]
  ------------------
  324|    369|			break;
  325|    369|		}
  326|  16.4k|		*len = bebytes2ushort(attr + sizeof(coolkey_attribute_header_t));
  327|  16.4k|		if (encoded_len) {
  ------------------
  |  Branch (327:7): [True: 14.8k, False: 1.61k]
  ------------------
  328|  14.8k|			*len += 2;
  329|  14.8k|		}
  330|  16.4k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
  331|  1.39k|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|  1.39k|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (331:2): [True: 1.39k, False: 27.2k]
  ------------------
  332|  2.13k|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|  2.13k|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (332:2): [True: 738, False: 27.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|  2.13k|		*len = encoded_len ? 0: 1;
  ------------------
  |  Branch (335:10): [True: 2.13k, False: 0]
  ------------------
  336|  2.13k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.13k|#define SC_SUCCESS				0
  ------------------
  337|      0|		break;
  338|  3.34k|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|  3.34k|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (338:2): [True: 3.34k, False: 25.3k]
  ------------------
  339|  3.34k|		*len = 4; /* length is 4 in both encoded length and attribute length */
  340|  3.34k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.34k|#define SC_SUCCESS				0
  ------------------
  341|  6.35k|	default:
  ------------------
  |  Branch (341:2): [True: 6.35k, False: 22.3k]
  ------------------
  342|  6.35k|		break;
  343|  28.6k|	}
  344|  6.72k|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  6.72k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  345|  28.6k|}
card-coolkey.c:coolkey_read_object:
 1100|  35.3k|{
 1101|  35.3k|	coolkey_read_object_param_t params;
 1102|  35.3k|	u8 *out_ptr;
 1103|  35.3k|	size_t left = 0;
 1104|  35.3k|	size_t len;
 1105|  35.3k|	int r;
 1106|       |
 1107|  35.3k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  35.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  35.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  35.3k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 35.3k]
  |  |  ------------------
  ------------------
 1108|       |
 1109|  35.3k|	ulong2bebytes(&params.object_id[0], object_id);
 1110|       |
 1111|  35.3k|	out_ptr = out_buf;
 1112|  35.3k|	left = out_len;
 1113|  45.9k|	do {
 1114|  45.9k|		ulong2bebytes(&params.offset[0], offset);
 1115|  45.9k|		params.length = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
  ------------------
  |  |   70|  45.9k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 37.1k, False: 8.78k]
  |  |  ------------------
  ------------------
 1116|  45.9k|		len = left;
 1117|  45.9k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   72|  45.9k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   88|  45.9k|#define COOLKEY_INS_READ_OBJECT                0x56
  ------------------
 1118|  45.9k|			(u8 *)&params, sizeof(params), &out_ptr, &len, nonce, nonce_size);
 1119|  45.9k|		if (r < 0) {
  ------------------
  |  Branch (1119:7): [True: 31.3k, False: 14.5k]
  ------------------
 1120|  31.3k|			goto fail;
 1121|  31.3k|		}
 1122|       |		/* sanity check to make sure we don't overflow left */
 1123|  14.5k|		if ((left < len) || (len == 0)) {
  ------------------
  |  Branch (1123:7): [True: 316, False: 14.2k]
  |  Branch (1123:23): [True: 1.15k, False: 13.0k]
  ------------------
 1124|  1.47k|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.47k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1125|  1.47k|			goto fail;
 1126|  1.47k|		}
 1127|  13.0k|		out_ptr += len;
 1128|  13.0k|		offset += len;
 1129|  13.0k|		left -= len;
 1130|  13.0k|	} while (left != 0);
  ------------------
  |  Branch (1130:11): [True: 10.5k, False: 2.57k]
  ------------------
 1131|       |
 1132|  2.57k|	return (int)out_len;
 1133|       |
 1134|  32.8k|fail:
 1135|  32.8k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  32.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  32.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  32.8k|	int _ret = r; \
  |  |  |  |  155|  32.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  32.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|  32.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  32.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  32.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|  32.8k|	return _ret; \
  |  |  |  |  163|  32.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1136|  32.8k|}
card-coolkey.c:coolkey_apdu_io:
  912|  72.4k|{
  913|  72.4k|	int r;
  914|  72.4k|	sc_apdu_t apdu;
  915|  72.4k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  916|  72.4k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  917|  72.4k|	u8 *rbuf;
  918|  72.4k|	size_t rbuflen;
  919|  72.4k|	int cse = 0;
  920|       |
  921|       |
  922|  72.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  72.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  72.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  72.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 72.4k]
  |  |  ------------------
  ------------------
  923|       |
  924|  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__
  |  |  ------------------
  ------------------
  925|  72.4k|		 "%02x %02x %02x %"SC_FORMAT_LEN_SIZE_T"u : %"SC_FORMAT_LEN_SIZE_T"u %"SC_FORMAT_LEN_SIZE_T"u\n",
  926|  72.4k|		 ins, p1, p2, sendbuflen, card->max_send_size,
  927|  72.4k|		 card->max_recv_size);
  928|       |
  929|  72.4k|	rbuf = rbufinitbuf;
  930|  72.4k|	rbuflen = sizeof(rbufinitbuf);
  931|       |
  932|       |	/* if caller provided a buffer and length */
  933|  72.4k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (933:6): [True: 59.5k, False: 12.8k]
  |  Branch (933:17): [True: 59.5k, False: 0]
  |  Branch (933:29): [True: 59.5k, False: 0]
  |  Branch (933:43): [True: 56.9k, False: 2.64k]
  ------------------
  934|  56.9k|		rbuf = *recvbuf;
  935|  56.9k|		rbuflen = *recvbuflen;
  936|  56.9k|	}
  937|       |
  938|  72.4k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (938:6): [True: 58.9k, False: 13.4k]
  |  Branch (938:17): [True: 0, False: 13.4k]
  ------------------
  939|  58.9k|		if (recvbuf) {
  ------------------
  |  Branch (939:7): [True: 46.0k, False: 12.8k]
  ------------------
  940|  46.0k|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  46.0k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  941|  46.0k|		} else {
  942|  12.8k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  12.8k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  943|  12.8k|		}
  944|  58.9k|	} else {
  945|  13.4k|		if (recvbuf) {
  ------------------
  |  Branch (945:7): [True: 13.4k, False: 0]
  ------------------
  946|  13.4k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  13.4k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  947|  13.4k|		} else {
  948|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  949|      0|		}
  950|  13.4k|	}
  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|  72.4k|	if (nonce) {
  ------------------
  |  Branch (957:6): [True: 47.9k, False: 24.4k]
  ------------------
  958|  47.9k|		u8 *buf = rsendbuf;
  959|  47.9k|		if (sendbuf) {
  ------------------
  |  Branch (959:7): [True: 47.9k, False: 0]
  ------------------
  960|  47.9k|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   70|  47.9k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 47.9k, False: 0]
  |  |  ------------------
  ------------------
  961|  47.9k|			memcpy(rsendbuf, sendbuf, sendbuflen);
  962|  47.9k|			buf += sendbuflen;
  963|  47.9k|		}
  964|  47.9k|		memcpy(buf, nonce, nonce_len);
  965|  47.9k|		sendbuflen += nonce_len;
  966|  47.9k|		sendbuf =rsendbuf;
  967|  47.9k|	}
  968|       |
  969|  72.4k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  970|       |
  971|  72.4k|	apdu.lc = sendbuflen;
  972|  72.4k|	apdu.datalen = sendbuflen;
  973|  72.4k|	apdu.data = sendbuf;
  974|       |
  975|       |
  976|       |	/* coolkey uses non-standard classes */
  977|  72.4k|	apdu.cla = cla;
  978|       |
  979|  72.4k|	if (recvbuf) {
  ------------------
  |  Branch (979:6): [True: 59.5k, False: 12.8k]
  ------------------
  980|  59.5k|		apdu.resp = rbuf;
  981|  59.5k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (981:13): [True: 10.2k, False: 49.3k]
  ------------------
  982|  59.5k|		apdu.resplen = rbuflen;
  983|  59.5k|	} else {
  984|  12.8k|		 apdu.resp =  rbuf;
  985|  12.8k|		 apdu.le = 0;
  986|  12.8k|		 apdu.resplen = 0;
  987|  12.8k|	}
  988|       |
  989|  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__
  |  |  ------------------
  ------------------
  990|  72.4k|		 "calling sc_transmit_apdu flags=%lx le=%"SC_FORMAT_LEN_SIZE_T"u, resplen=%"SC_FORMAT_LEN_SIZE_T"u, resp=%p",
  991|  72.4k|		 apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  992|       |
  993|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  994|  72.4k|	r = sc_transmit_apdu(card, &apdu);
  995|       |
  996|  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__
  |  |  ------------------
  ------------------
  997|  72.4k|		 "result r=%d apdu.resplen=%"SC_FORMAT_LEN_SIZE_T"u sw1=%02x sw2=%02x",
  998|  72.4k|		 r, apdu.resplen, apdu.sw1, apdu.sw2);
  999|       |
 1000|  72.4k|	if (r < 0) {
  ------------------
  |  Branch (1000:6): [True: 841, False: 71.5k]
  ------------------
 1001|    841|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    841|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1002|    841|		goto err;
 1003|    841|	}
 1004|  71.5k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1005|  71.5k|	if (r < 0) {
  ------------------
  |  Branch (1005:6): [True: 39.4k, False: 32.1k]
  ------------------
 1006|  39.4k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  39.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__
  |  |  ------------------
  ------------------
 1007|  39.4k|		goto err;
 1008|  39.4k|	}
 1009|       |
 1010|  32.1k|	if (recvbuflen) {
  ------------------
  |  Branch (1010:6): [True: 27.1k, False: 4.97k]
  ------------------
 1011|  27.1k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1011:7): [True: 27.1k, False: 49]
  |  Branch (1011:18): [True: 0, False: 27.1k]
  ------------------
 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.1k|		*recvbuflen =  apdu.resplen;
 1020|  27.1k|		r = (int)*recvbuflen;
 1021|  27.1k|	}
 1022|       |
 1023|  72.4k|err:
 1024|  72.4k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  72.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  72.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  72.4k|	int _ret = r; \
  |  |  |  |  155|  72.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 46.4k, False: 25.9k]
  |  |  |  |  ------------------
  |  |  |  |  156|  46.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|  40.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 40.2k, False: 6.22k]
  |  |  |  |  ------------------
  |  |  |  |  157|  46.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  46.4k|	} else { \
  |  |  |  |  159|  25.9k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  25.9k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  25.9k|	} \
  |  |  |  |  162|  72.4k|	return _ret; \
  |  |  |  |  163|  72.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1025|  72.4k|}
card-coolkey.c:coolkey_find_object_by_id:
  825|  15.5k|{
  826|  15.5k|	int pos;
  827|  15.5k|	static sc_cardctl_coolkey_object_t cmp = {{
  828|  15.5k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  15.5k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  829|  15.5k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  15.5k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  15.5k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  830|  15.5k|	}, 0, 0, NULL};
  831|       |
  832|  15.5k|	cmp.id = object_id;
  833|  15.5k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (833:6): [True: 9.36k, False: 6.16k]
  ------------------
  834|  9.36k|		return NULL;
  835|       |
  836|  6.16k|	return list_get_at(list, pos);
  837|  15.5k|}
card-coolkey.c:coolkey_find_attribute:
 1424|  86.1k|{
 1425|  86.1k|	u8 object_record_type;
 1426|  86.1k|	CK_ATTRIBUTE_TYPE attr_type = attribute->attribute_type;
 1427|  86.1k|	const u8 *obj = attribute->object->data;
 1428|  86.1k|	const u8 *attr = NULL;
 1429|  86.1k|	size_t buf_len = attribute->object->length;
 1430|  86.1k|	coolkey_object_header_t *object_head;
 1431|  86.1k|	int attribute_count,i;
 1432|  86.1k|	attribute->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1048|  86.1k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
 1433|  86.1k|	attribute->attribute_length = 0;
 1434|  86.1k|	attribute->attribute_value = NULL;
 1435|       |
 1436|  86.1k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  86.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  86.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  86.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  86.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 86.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1437|       |
 1438|  86.1k|	if (obj == NULL) {
  ------------------
  |  Branch (1438:6): [True: 34.9k, False: 51.1k]
  ------------------
 1439|       |		/* cast away const so we can cache the data value */
 1440|  34.9k|		int r = coolkey_fill_object(card, (sc_cardctl_coolkey_object_t *)attribute->object);
 1441|  34.9k|		if (r < 0) {
  ------------------
  |  Branch (1441:7): [True: 32.6k, False: 2.33k]
  ------------------
 1442|  32.6k|			return r;
 1443|  32.6k|		}
 1444|  2.33k|		obj = attribute->object->data;
 1445|  2.33k|		if (obj == NULL) {
  ------------------
  |  Branch (1445:7): [True: 0, False: 2.33k]
  ------------------
 1446|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1447|      0|		}
 1448|  2.33k|	}
 1449|       |
 1450|       |	/* should be a static assert so we catch this at compile time */
 1451|  86.1k|	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|  53.4k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (1453:6): [True: 687, False: 52.8k]
  ------------------
 1454|    687|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    687|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1455|    687|	}
 1456|  52.8k|	object_head = (coolkey_object_header_t *)obj;
 1457|  52.8k|	object_record_type = object_head->record_type;
 1458|       |	/* make sure it's a type we recognize */
 1459|  52.8k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  52.8k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  6.30k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (1459:6): [True: 6.30k, False: 46.4k]
  |  Branch (1459:51): [True: 4.49k, False: 1.81k]
  ------------------
 1460|  4.49k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  4.49k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1461|  4.49k|	}
 1462|       |
 1463|       |	/*
 1464|       |	 * now loop through all the attributes in the list. first find the start of the list
 1465|       |	 */
 1466|  48.3k|	attr = coolkey_attribute_start(obj, object_record_type, buf_len);
 1467|  48.3k|	if (attr == NULL) {
  ------------------
  |  Branch (1467:6): [True: 144, False: 48.1k]
  ------------------
 1468|    144|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    144|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1469|    144|	}
 1470|  48.1k|	buf_len -= (attr-obj);
 1471|       |
 1472|       |	/* now get the count */
 1473|  48.1k|	attribute_count = coolkey_get_attribute_count(obj, object_record_type, buf_len);
 1474|  73.0k|	for (i=0; i < attribute_count; i++) {
  ------------------
  |  Branch (1474:12): [True: 28.4k, False: 44.5k]
  ------------------
 1475|  28.4k|		size_t record_len = coolkey_get_attribute_record_len(attr, object_record_type, buf_len);
 1476|       |		/* make sure we have the complete record */
 1477|  28.4k|		if (buf_len < record_len || record_len < 4) {
  ------------------
  |  Branch (1477:7): [True: 0, False: 28.4k]
  |  Branch (1477:31): [True: 879, False: 27.5k]
  ------------------
 1478|    879|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    879|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1479|    879|		}
 1480|       |		/* does the attribute match the one we are looking for */
 1481|  27.5k|		if (attr_type == coolkey_get_attribute_type(attr, object_record_type, record_len)) {
  ------------------
  |  Branch (1481:7): [True: 2.70k, False: 24.8k]
  ------------------
 1482|       |			/* yup, return it */
 1483|  2.70k|			return coolkey_get_attribute_data(attr, object_record_type, record_len, attribute);
 1484|  2.70k|		}
 1485|       |		/* go to the next attribute on the list */
 1486|  24.8k|		buf_len -= record_len;
 1487|  24.8k|		attr += record_len;
 1488|  24.8k|	}
 1489|       |	/* not find in attribute list, check the fixed attribute record */
 1490|  44.5k|	if (object_record_type == COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  44.5k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (1490:6): [True: 42.8k, False: 1.68k]
  ------------------
 1491|  42.8k|		unsigned long fixed_attributes = bebytes2ulong(object_head->fixed_attributes_values);
 1492|       |
 1493|  42.8k|		return coolkey_get_attribute_data_fixed(attr_type, fixed_attributes, attribute);
 1494|  42.8k|	}
 1495|  1.68k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  1.68k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.68k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.68k|	int _ret = r; \
  |  |  |  |  155|  1.68k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.68k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.68k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.68k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.68k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.68k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.68k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.68k|	return _ret; \
  |  |  |  |  163|  1.68k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1496|  1.68k|}
card-coolkey.c:coolkey_attribute_start:
  421|  49.9k|{
  422|  49.9k|	size_t offset = object_record_type == COOLKEY_V1_OBJECT ? sizeof(coolkey_object_header_t) :
  ------------------
  |  |  229|  49.9k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (422:18): [True: 46.4k, False: 3.44k]
  ------------------
  423|  49.9k|			sizeof(coolkey_v0_object_header_t);
  424|       |
  425|  49.9k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  49.9k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  3.44k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (425:6): [True: 3.44k, False: 46.4k]
  |  Branch (425:51): [True: 0, False: 3.44k]
  ------------------
  426|      0|		return NULL;
  427|      0|	}
  428|  49.9k|	if (offset > buf_len) {
  ------------------
  |  Branch (428:6): [True: 144, False: 49.8k]
  ------------------
  429|    144|		return NULL;
  430|    144|	}
  431|  49.8k|	return obj + offset;
  432|  49.9k|}
card-coolkey.c:coolkey_get_attribute_count:
  502|  48.1k|{
  503|  48.1k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  48.1k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (503:6): [True: 1.81k, False: 46.3k]
  ------------------
  504|  1.81k|		return coolkey_v0_get_attribute_count(obj, buf_len);
  505|  1.81k|	}
  506|  46.3k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  46.3k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (506:6): [True: 0, False: 46.3k]
  ------------------
  507|      0|		return 0;
  508|      0|	}
  509|  46.3k|	return coolkey_v1_get_attribute_count(obj, buf_len);
  510|  46.3k|}
card-coolkey.c:coolkey_v0_get_attribute_count:
  440|  1.81k|{
  441|  1.81k|	coolkey_v0_object_header_t *object_head = (coolkey_v0_object_header_t *)obj;
  442|  1.81k|	const u8 *attr;
  443|  1.81k|	int count = 0;
  444|  1.81k|	size_t attribute_data_len;
  445|       |
  446|       |	/* make sure we have enough of the object to read the record_type */
  447|  1.81k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (447:6): [True: 177, False: 1.63k]
  ------------------
  448|    177|		return 0;
  449|    177|	}
  450|       |	/*
  451|       |	 * now loop through all the attributes in the list. first find the start of the list
  452|       |	 */
  453|  1.63k|	attr = coolkey_attribute_start(obj, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|  1.63k|#define COOLKEY_V0_OBJECT 0
  ------------------
  454|  1.63k|	if (attr == NULL) {
  ------------------
  |  Branch (454:6): [True: 0, False: 1.63k]
  ------------------
  455|      0|		return 0;
  456|      0|	}
  457|       |
  458|  1.63k|	buf_len -= (attr-obj);
  459|  1.63k|	attribute_data_len = bebytes2ushort(object_head->attribute_data_len);
  460|  1.63k|	if (buf_len < attribute_data_len) {
  ------------------
  |  Branch (460:6): [True: 349, False: 1.28k]
  ------------------
  461|    349|		return 0;
  462|    349|	}
  463|       |
  464|  2.68k|	while (attribute_data_len) {
  ------------------
  |  Branch (464:9): [True: 1.68k, False: 997]
  ------------------
  465|  1.68k|		size_t len = coolkey_v0_get_attribute_record_len(attr, buf_len);
  466|       |
  467|  1.68k|		if (len == 0) {
  ------------------
  |  Branch (467:7): [True: 0, False: 1.68k]
  ------------------
  468|      0|			break;
  469|      0|		}
  470|       |		/*  This is an error in the token data, don't parse the last attribute */
  471|  1.68k|		if (len > attribute_data_len) {
  ------------------
  |  Branch (471:7): [True: 289, False: 1.39k]
  ------------------
  472|    289|			break;
  473|    289|		}
  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.39k|		if (len > buf_len)
  ------------------
  |  Branch (479:7): [True: 0, False: 1.39k]
  ------------------
  480|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  481|  1.39k|		count++;
  482|  1.39k|		attr += len;
  483|  1.39k|		buf_len -= len;
  484|  1.39k|		attribute_data_len -= len;
  485|  1.39k|	}
  486|  1.28k|	return count;
  487|  1.28k|}
card-coolkey.c:coolkey_v0_get_attribute_record_len:
  380|  2.85k|{
  381|  2.85k|	size_t attribute_len = sizeof(coolkey_v0_attribute_header_t);
  382|  2.85k|	size_t len;
  383|  2.85k|	int r;
  384|       |
  385|  2.85k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  386|  2.85k|	if (r < 0) {
  ------------------
  |  Branch (386:6): [True: 98, False: 2.75k]
  ------------------
  387|     98|		return buf_len; /* skip to the end, ignore the rest of the record */
  388|     98|	}
  389|  2.75k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  2.75k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 456, False: 2.30k]
  |  |  ------------------
  ------------------
  390|  2.85k|}
card-coolkey.c:coolkey_v1_get_attribute_count:
  491|  46.3k|{
  492|  46.3k|	coolkey_object_header_t *object_head = (coolkey_object_header_t *)obj;
  493|       |
  494|  46.3k|	if (buf_len <= sizeof(coolkey_object_header_t)) {
  ------------------
  |  Branch (494:6): [True: 19.9k, False: 26.4k]
  ------------------
  495|  19.9k|		return 0;
  496|  19.9k|	}
  497|  26.4k|	return bebytes2ushort(object_head->attribute_count);
  498|  46.3k|}
card-coolkey.c:coolkey_get_attribute_record_len:
  394|  28.4k|{
  395|  28.4k|	if (obj_record_type ==  COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  28.4k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (395:6): [True: 1.16k, False: 27.2k]
  ------------------
  396|  1.16k|		return coolkey_v0_get_attribute_record_len(attr, buf_len);
  397|  1.16k|	}
  398|  27.2k|	if (obj_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  27.2k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (398:6): [True: 0, False: 27.2k]
  ------------------
  399|      0|		return buf_len; /* skip to the end */
  400|      0|	}
  401|  27.2k|	return coolkey_v1_get_attribute_record_len(attr, buf_len);
  402|  27.2k|}
card-coolkey.c:coolkey_v1_get_attribute_record_len:
  364|   140k|{
  365|   140k|	size_t attribute_len = sizeof(coolkey_attribute_header_t);
  366|   140k|	size_t len = 0;
  367|   140k|	int r;
  368|       |
  369|   140k|	r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 1);
  370|   140k|	if (r < 0) {
  ------------------
  |  Branch (370:6): [True: 120k, False: 20.3k]
  ------------------
  371|   120k|		return buf_len; /* skip to the end, ignore the rest of the record */
  372|   120k|	}
  373|       |
  374|  20.3k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  20.3k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 1.10k, False: 19.2k]
  |  |  ------------------
  ------------------
  375|   140k|}
card-coolkey.c:coolkey_get_attribute_data_fixed:
  674|  42.8k|																sc_cardctl_coolkey_attribute_t *attr_out) {
  675|  42.8k|	unsigned long cka_id = fixed_attributes & 0xf;
  676|  42.8k|	unsigned long cka_class = ((fixed_attributes) >> 4) & 0x7;
  677|  42.8k|	unsigned long mask, bit;
  678|       |
  679|  42.8k|	if (attr_type == CKA_ID) {
  ------------------
  |  |  161|  42.8k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (679:6): [True: 5.48k, False: 37.4k]
  ------------------
  680|  5.48k|		attr_out->attribute_length = 1;
  681|  5.48k|		attr_out->attribute_value= &coolkey_static_cka_id[cka_id];
  682|  5.48k|		return SC_SUCCESS;
  ------------------
  |  |   28|  5.48k|#define SC_SUCCESS				0
  ------------------
  683|  5.48k|	}
  684|  37.4k|	if (attr_type == CKA_CLASS) {
  ------------------
  |  |  137|  37.4k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (684:6): [True: 10.6k, False: 26.8k]
  ------------------
  685|  10.6k|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|  10.6k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  686|  10.6k|		attr_out->attribute_length = 4;
  687|  10.6k|		attr_out->attribute_value = coolkey_static_cka_class[cka_class].class_value;
  688|  10.6k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.6k|#define SC_SUCCESS				0
  ------------------
  689|  10.6k|	}
  690|       |	/* If it matched, it must be one of the booleans */
  691|  26.8k|	mask = coolkey_static_cka_class[cka_class].boolean_mask;
  692|  26.8k|	bit = coolkey_get_fixed_boolean_bit(attr_type);
  693|       |	/* attribute isn't in the list */
  694|  26.8k|	if ((bit & mask) == 0) {
  ------------------
  |  Branch (694:6): [True: 10.4k, False: 16.3k]
  ------------------
  695|  10.4k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  10.4k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  696|  10.4k|	}
  697|  16.3k|	attr_out->attribute_length = 1;
  698|  16.3k|	attr_out->attribute_value = bit & fixed_attributes ? &coolkey_static_true : &coolkey_static_false;
  ------------------
  |  Branch (698:30): [True: 6.89k, False: 9.49k]
  ------------------
  699|  16.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.3k|#define SC_SUCCESS				0
  ------------------
  700|  26.8k|}
card-coolkey.c:coolkey_get_fixed_boolean_bit:
  620|  26.8k|{
  621|  26.8k|	switch(type) {
  622|      0|	case CKA_TOKEN:               return 0x00000080;
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (622:2): [True: 0, False: 26.8k]
  ------------------
  623|  2.15k|	case CKA_PRIVATE:             return 0x00000100;
  ------------------
  |  |  139|  2.15k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (623:2): [True: 2.15k, False: 24.6k]
  ------------------
  624|  2.58k|	case CKA_MODIFIABLE:          return 0x00000200;
  ------------------
  |  |  197|  2.58k|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (624:2): [True: 2.58k, False: 24.2k]
  ------------------
  625|  1.26k|	case CKA_DERIVE:              return 0x00000400;
  ------------------
  |  |  171|  1.26k|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (625:2): [True: 1.26k, False: 25.5k]
  ------------------
  626|  1.26k|	case CKA_LOCAL:               return 0x00000800;
  ------------------
  |  |  193|  1.26k|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (626:2): [True: 1.26k, False: 25.5k]
  ------------------
  627|  1.26k|	case CKA_ENCRYPT:             return 0x00001000;
  ------------------
  |  |  163|  1.26k|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (627:2): [True: 1.26k, False: 25.5k]
  ------------------
  628|  1.26k|	case CKA_DECRYPT:             return 0x00002000;
  ------------------
  |  |  164|  1.26k|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (628:2): [True: 1.26k, False: 25.5k]
  ------------------
  629|  1.25k|	case CKA_WRAP:                return 0x00004000;
  ------------------
  |  |  165|  1.25k|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (629:2): [True: 1.25k, False: 25.5k]
  ------------------
  630|  1.26k|	case CKA_UNWRAP:              return 0x00008000;
  ------------------
  |  |  166|  1.26k|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (630:2): [True: 1.26k, False: 25.5k]
  ------------------
  631|  1.26k|	case CKA_SIGN:                return 0x00010000;
  ------------------
  |  |  167|  1.26k|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (631:2): [True: 1.26k, False: 25.5k]
  ------------------
  632|  1.26k|	case CKA_SIGN_RECOVER:        return 0x00020000;
  ------------------
  |  |  168|  1.26k|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (632:2): [True: 1.26k, False: 25.5k]
  ------------------
  633|  1.26k|	case CKA_VERIFY:              return 0x00040000;
  ------------------
  |  |  169|  1.26k|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (633:2): [True: 1.26k, False: 25.5k]
  ------------------
  634|  1.26k|	case CKA_VERIFY_RECOVER:      return 0x00080000;
  ------------------
  |  |  170|  1.26k|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (634:2): [True: 1.26k, False: 25.5k]
  ------------------
  635|  1.25k|	case CKA_SENSITIVE:           return 0x00100000;
  ------------------
  |  |  162|  1.25k|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (635:2): [True: 1.25k, False: 25.5k]
  ------------------
  636|  1.26k|	case CKA_ALWAYS_SENSITIVE:    return 0x00200000;
  ------------------
  |  |  195|  1.26k|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (636:2): [True: 1.26k, False: 25.5k]
  ------------------
  637|  1.26k|	case CKA_EXTRACTABLE:         return 0x00400000;
  ------------------
  |  |  192|  1.26k|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (637:2): [True: 1.26k, False: 25.5k]
  ------------------
  638|  1.26k|	case CKA_NEVER_EXTRACTABLE:   return 0x00800000;
  ------------------
  |  |  194|  1.26k|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (638:2): [True: 1.26k, False: 25.5k]
  ------------------
  639|  4.43k|	default: break;
  ------------------
  |  Branch (639:2): [True: 4.43k, False: 22.3k]
  ------------------
  640|  26.8k|	}
  641|  4.43k|	return 0; /* return no bits */
  642|  26.8k|}
card-coolkey.c:sc_get_driver:
 2449|  16.4k|{
 2450|  16.4k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2451|       |
 2452|  16.4k|	coolkey_ops = *iso_drv->ops;
 2453|  16.4k|	coolkey_ops.match_card = coolkey_match_card;
 2454|  16.4k|	coolkey_ops.init = coolkey_init;
 2455|  16.4k|	coolkey_ops.finish = coolkey_finish;
 2456|       |
 2457|  16.4k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2458|  16.4k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2459|  16.4k|	coolkey_ops.read_binary = coolkey_read_binary;
 2460|  16.4k|	coolkey_ops.write_binary = coolkey_write_binary;
 2461|  16.4k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2462|  16.4k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2463|  16.4k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2464|  16.4k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2465|  16.4k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2466|  16.4k|	coolkey_ops.check_sw = coolkey_check_sw;
 2467|  16.4k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2468|  16.4k|	coolkey_ops.logout = coolkey_logout;
 2469|  16.4k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2470|       |
 2471|  16.4k|	return &coolkey_drv;
 2472|  16.4k|}
card-coolkey.c:coolkey_match_card:
 2288|  7.29k|{
 2289|  7.29k|	int r;
 2290|       |
 2291|  7.29k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.29k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.29k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.29k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.29k]
  |  |  ------------------
  ------------------
 2292|       |
 2293|  7.29k|	r = coolkey_select_applet(card);
 2294|  7.29k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  7.29k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2294:6): [True: 1.34k, False: 5.95k]
  ------------------
 2295|  1.34k|		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.34k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|  1.34k|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   79|  1.34k|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2302|  1.34k|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   72|  1.34k|#define COOLKEY_CLASS           0xb0
  ------------------
 2303|  1.34k|		apdu.le = 0x00;
 2304|  1.34k|		apdu.resplen = 0;
 2305|  1.34k|		apdu.resp = NULL;
 2306|  1.34k|		r = sc_transmit_apdu(card, &apdu);
 2307|  1.34k|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|  2.68k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2307:7): [True: 1.33k, False: 2]
  |  Branch (2307:26): [True: 1.10k, False: 238]
  |  Branch (2307:46): [True: 1.09k, False: 6]
  ------------------
 2308|  1.09k|			return 1;
 2309|  1.09k|		}
 2310|    246|		return 0;
 2311|  1.34k|	}
 2312|  5.95k|	return 0;
 2313|  7.29k|}
card-coolkey.c:coolkey_select_applet:
 1074|  10.9k|{
 1075|  10.9k|	u8 aid[] = { 0x62, 0x76, 0x01, 0xff, 0x00, 0x00, 0x00 };
 1076|  10.9k|	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   71|  10.9k|#define ISO7816_CLASS           0x00
  ------------------
              	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   75|  10.9k|#define ISO7816_INS_SELECT_FILE 0xa4
  ------------------
 1077|  10.9k|			&aid[0], sizeof(aid), NULL, NULL,  NULL, 0);
 1078|  10.9k|}
card-coolkey.c:coolkey_init:
 2317|  1.09k|{
 2318|  1.09k|	int r;
 2319|  1.09k|	unsigned long flags;
 2320|  1.09k|	unsigned long ext_flags;
 2321|  1.09k|	coolkey_private_data_t * priv;
 2322|       |
 2323|  1.09k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.09k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
 2324|       |
 2325|  1.09k|	r = coolkey_initialize(card);
 2326|  1.09k|	if (r < 0) {
  ------------------
  |  Branch (2326:6): [True: 414, False: 680]
  ------------------
 2327|    414|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    414|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    414|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    414|	int _ret = r; \
  |  |  |  |  155|    414|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 414, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    414|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    414|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 414, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    414|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    414|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    414|	return _ret; \
  |  |  |  |  163|    414|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2328|    414|	}
 2329|       |
 2330|    680|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2331|       |
 2332|       |	/* set Token Major/minor version */
 2333|    680|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  111|    680|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2334|       |
 2335|    680|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2336|    680|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2337|    680|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2338|       |
 2339|    680|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  183|    680|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  182|    680|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|    680|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    680|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2340|    680|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|    680|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|    680|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2341|       |
 2342|    680|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2343|    680|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2344|    680|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2345|       |
 2346|       |
 2347|    680|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    680|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2348|    680|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2348:6): [True: 399, False: 281]
  ------------------
 2349|    399|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    399|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2350|    399|	}
 2351|       |
 2352|    680|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    680|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    680|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    680|	int _ret = r; \
  |  |  |  |  155|    680|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    680|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 680]
  |  |  |  |  ------------------
  |  |  |  |  157|    680|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    680|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    680|	return _ret; \
  |  |  |  |  163|    680|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2353|    680|}
card-coolkey.c:coolkey_initialize:
 2157|  1.09k|{
 2158|  1.09k|	int r;
 2159|  1.09k|	coolkey_private_data_t *priv = NULL;
 2160|  1.09k|	coolkey_life_cycle_t life_cycle;
 2161|  1.09k|	coolkey_object_info_t object_info;
 2162|  1.09k|	int combined_processed = 0;
 2163|       |
 2164|       |	/* already found? */
 2165|  1.09k|	if (card->drv_data) {
  ------------------
  |  Branch (2165:6): [True: 0, False: 1.09k]
  ------------------
 2166|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2167|      0|	}
 2168|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2169|       |
 2170|  1.09k|	priv = coolkey_new_private_data();
 2171|  1.09k|	if (priv == NULL) {
  ------------------
  |  Branch (2171:6): [True: 0, False: 1.09k]
  ------------------
 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.09k|	r = coolkey_get_life_cycle(card, &life_cycle);
 2176|  1.09k|	if (r < 0) {
  ------------------
  |  Branch (2176:6): [True: 87, False: 1.00k]
  ------------------
 2177|     87|		goto cleanup;
 2178|     87|	}
 2179|       |
 2180|       |	/* Select a coolkey read the coolkey objects out */
 2181|  1.00k|	r = coolkey_select_applet(card);
 2182|  1.00k|	if (r < 0) {
  ------------------
  |  Branch (2182:6): [True: 7, False: 1.00k]
  ------------------
 2183|      7|		goto cleanup;
 2184|      7|	}
 2185|       |
 2186|  1.00k|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2187|  1.00k|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2188|  1.00k|	priv->pin_count = life_cycle.pin_count;
 2189|  1.00k|	priv->life_cycle = life_cycle.life_cycle;
 2190|       |
 2191|       |	/* walk down the list of objects and read them off the token */
 2192|  1.00k|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  104|  1.00k|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2193|  12.2k|	while (r >= 0) {
  ------------------
  |  Branch (2193:9): [True: 11.4k, False: 870]
  ------------------
 2194|  11.4k|		unsigned long object_id;
 2195|  11.4k|		unsigned long object_len;
 2196|       |
 2197|       |		/* The card did not return what we expected: Lets try other objects */
 2198|  11.4k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2198:7): [True: 8, False: 11.4k]
  ------------------
 2199|      8|			break;
 2200|       |
 2201|       |		/* TODO also look at the ACL... */
 2202|       |
 2203|  11.4k|		object_id = bebytes2ulong(object_info.object_id);
 2204|  11.4k|		object_len = bebytes2ulong(object_info.object_length);
 2205|       |		/* Avoid insanely large data */
 2206|  11.4k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  11.4k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2206:7): [True: 13, False: 11.3k]
  ------------------
 2207|     13|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     13|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2208|     13|			goto cleanup;
 2209|     13|		}
 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.3k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  109|  11.3k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2217:7): [True: 231, False: 11.1k]
  ------------------
 2218|    231|			u8 *object = malloc(object_len);
 2219|    231|			if (object == NULL) {
  ------------------
  |  Branch (2219:8): [True: 0, False: 231]
  ------------------
 2220|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2221|      0|				break;
 2222|      0|			}
 2223|    231|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  109|    231|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2224|    231|				priv->nonce, sizeof(priv->nonce));
 2225|    231|			if (r < 0) {
  ------------------
  |  Branch (2225:8): [True: 52, False: 179]
  ------------------
 2226|     52|				free(object);
 2227|     52|				break;
 2228|     52|			}
 2229|    179|			r = coolkey_process_combined_object(card, priv, object, r);
 2230|    179|			free(object);
 2231|    179|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    179|#define SC_SUCCESS				0
  ------------------
  |  Branch (2231:8): [True: 57, False: 122]
  ------------------
 2232|     57|				break;
 2233|     57|			}
 2234|    122|			combined_processed = 1;
 2235|  11.1k|		} else {
 2236|  11.1k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2237|  11.1k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2238|  11.1k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  11.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2238:8): [True: 3.32k, False: 7.83k]
  ------------------
 2239|  3.32k|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
 2240|  11.1k|		}
 2241|       |
 2242|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2243|  11.2k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  105|  11.2k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2244|  11.2k|	}
 2245|    987|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    987|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2245:6): [True: 289, False: 698]
  ------------------
 2246|       |		/* This means the card does not cooperate at all: bail out */
 2247|    289|		if (r >= 0) {
  ------------------
  |  Branch (2247:7): [True: 8, False: 281]
  ------------------
 2248|      8|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      8|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2249|      8|		}
 2250|    289|		goto cleanup;
 2251|    289|	}
 2252|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2253|    698|	if (!combined_processed) {
  ------------------
  |  Branch (2253:6): [True: 580, False: 118]
  ------------------
 2254|    580|		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|    580|		r = gp_select_card_manager(card);
 2259|    580|		if (r < 0) {
  ------------------
  |  Branch (2259:7): [True: 6, False: 574]
  ------------------
 2260|      6|			goto cleanup;
 2261|      6|		}
 2262|       |
 2263|    574|		r = gp_get_cplc_data(card, &cplc_data);
 2264|    574|		if (r < 0) {
  ------------------
  |  Branch (2264:7): [True: 12, False: 562]
  ------------------
 2265|     12|			goto cleanup;
 2266|     12|		}
 2267|    562|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2268|    562|		priv->token_name = (u8 *)strdup("COOLKEY");
 2269|    562|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2269:7): [True: 0, False: 562]
  ------------------
 2270|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2271|      0|			goto cleanup;
 2272|      0|		}
 2273|    562|		priv->token_name_length = sizeof("COOLKEY")-1;
 2274|    562|	}
 2275|    680|	card->drv_data = priv;
 2276|    680|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    680|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    680|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    680|	int _ret = r; \
  |  |  |  |  155|    680|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    680|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 680]
  |  |  |  |  ------------------
  |  |  |  |  157|    680|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    680|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    680|	return _ret; \
  |  |  |  |  163|    680|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2277|       |
 2278|    414|cleanup:
 2279|    414|	if (priv) {
  ------------------
  |  Branch (2279:6): [True: 414, False: 0]
  ------------------
 2280|    414|		coolkey_free_private_data(priv);
 2281|    414|	}
 2282|    414|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    414|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    414|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    414|	int _ret = r; \
  |  |  |  |  155|    414|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 414, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    414|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    414|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 414, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    414|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    414|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    414|	return _ret; \
  |  |  |  |  163|    414|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2283|    414|}
card-coolkey.c:coolkey_new_private_data:
  772|  1.09k|{
  773|  1.09k|	coolkey_private_data_t *priv;
  774|       |
  775|       |	/* allocate priv and zero all the fields */
  776|  1.09k|	priv = calloc(1, sizeof(coolkey_private_data_t));
  777|  1.09k|	if (!priv)
  ------------------
  |  Branch (777:6): [True: 0, False: 1.09k]
  ------------------
  778|      0|		return NULL;
  779|       |
  780|       |	/* set other fields as appropriate */
  781|  1.09k|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|  1.09k|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  782|  1.09k|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (782:6): [True: 0, False: 1.09k]
  ------------------
  783|  1.09k|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 1.09k]
  ------------------
  784|  1.09k|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (784:6): [True: 0, False: 1.09k]
  ------------------
  785|      0|		coolkey_free_private_data(priv);
  786|      0|		return NULL;
  787|      0|	}
  788|       |
  789|  1.09k|	return priv;
  790|  1.09k|}
card-coolkey.c:coolkey_get_life_cycle:
 1032|  1.09k|{
 1033|  1.09k|	coolkey_status_t status;
 1034|  1.09k|	u8 *receive_buf;
 1035|  1.09k|	size_t receive_len;
 1036|  1.09k|	int len;
 1037|       |
 1038|  1.09k|	receive_len = sizeof(*life_cycle);
 1039|  1.09k|	receive_buf = (u8 *)life_cycle;
 1040|  1.09k|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|  1.09k|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|  1.09k|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1041|  1.09k|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1042|  1.09k|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1042:6): [True: 1.00k, False: 89]
  ------------------
 1043|  1.00k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.00k|#define SC_SUCCESS				0
  ------------------
 1044|  1.00k|	}
 1045|       |
 1046|     89|	receive_len = 1;
 1047|     89|	receive_buf = &life_cycle->life_cycle;
 1048|     89|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|     89|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|     89|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1049|     89|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1050|     89|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1050:6): [True: 72, False: 17]
  ------------------
 1051|     72|		return len;
 1052|     72|	}
 1053|     17|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1053:6): [True: 2, False: 15]
  ------------------
 1054|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1055|      2|	}
 1056|     15|	receive_len = sizeof(status);
 1057|     15|	receive_buf = (u8 *)&status;
 1058|     15|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   72|     15|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   79|     15|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1059|     15|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1060|     15|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1060:6): [True: 8, False: 7]
  ------------------
 1061|      8|		return len;
 1062|      8|	}
 1063|      7|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1063:6): [True: 5, False: 2]
  ------------------
 1064|      5|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      5|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1065|      5|	}
 1066|      2|	life_cycle->protocol_version_major = status.protocol_version_major;
 1067|      2|	life_cycle->protocol_version_minor = status.protocol_version_minor;
 1068|      2|	life_cycle->pin_count = status.pin_count;
 1069|      2|	return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 1070|      7|}
card-coolkey.c:coolkey_list_object:
 2144|  12.2k|{
 2145|  12.2k|	u8 *rbuf = (u8 *) object_info;
 2146|  12.2k|	size_t rbuflen = sizeof(*object_info);
 2147|       |
 2148|  12.2k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   72|  12.2k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   81|  12.2k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2149|  12.2k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2150|       |
 2151|  12.2k|}
card-coolkey.c:coolkey_process_combined_object:
 2013|    179|{
 2014|    179|	coolkey_combined_header_t *header = (coolkey_combined_header_t *)object;
 2015|    179|	unsigned short compressed_offset;
 2016|    179|	unsigned short compressed_length;
 2017|    179|	unsigned short compressed_type;
 2018|    179|	unsigned short object_offset;
 2019|    179|	unsigned short object_count;
 2020|    179|	coolkey_decompressed_header_t *decompressed_header;
 2021|    179|	u8 *decompressed_object = NULL;
 2022|    179|	size_t decompressed_object_len = 0;
 2023|    179|	int free_decompressed = 0;
 2024|    179|	int i, r;
 2025|       |
 2026|    179|	if (object_length < sizeof(coolkey_combined_header_t)) {
  ------------------
  |  Branch (2026:6): [True: 1, False: 178]
  ------------------
 2027|      1|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      1|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2028|      1|	}
 2029|    178|	compressed_offset = bebytes2ushort(header->compression_offset);
 2030|    178|	compressed_length = bebytes2ushort(header->compression_length);
 2031|    178|	compressed_type   = bebytes2ushort(header->compression_type);
 2032|       |
 2033|    178|	if ((((size_t)compressed_offset) + (size_t)compressed_length) >  object_length) {
  ------------------
  |  Branch (2033:6): [True: 8, False: 170]
  ------------------
 2034|      8|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      8|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2035|      8|	}
 2036|       |
 2037|       |	/* store the CUID */
 2038|    170|	memcpy(&priv->cuid, &header->cuid, sizeof(priv->cuid));
 2039|       |
 2040|    170|	if (compressed_type == COOLKEY_COMPRESSION_ZLIB) {
  ------------------
  |  |  180|    170|#define COOLKEY_COMPRESSION_ZLIB 1
  ------------------
  |  Branch (2040:6): [True: 134, False: 36]
  ------------------
 2041|    134|#ifdef ENABLE_ZLIB
 2042|    134|		r = sc_decompress_alloc(&decompressed_object, &decompressed_object_len, &object[compressed_offset], compressed_length, COMPRESSION_AUTO);
  ------------------
  |  |   26|    134|#define COMPRESSION_AUTO	0
  ------------------
 2043|    134|		if (r)
  ------------------
  |  Branch (2043:7): [True: 12, False: 122]
  ------------------
 2044|     12|			goto done;
 2045|    122|		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|    122|	}  else {
 2051|     36|		decompressed_object =&object[compressed_offset];
 2052|     36|		decompressed_object_len = (size_t) compressed_length;
 2053|     36|	}
 2054|       |
 2055|    158|	decompressed_header = (coolkey_decompressed_header_t *)decompressed_object;
 2056|       |
 2057|    158|	if (decompressed_object_len < sizeof(coolkey_decompressed_header_t)) {
  ------------------
  |  Branch (2057:6): [True: 5, False: 153]
  ------------------
 2058|      5|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      5|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2059|      5|		goto done;
 2060|      5|	}
 2061|    153|	object_offset = bebytes2ushort(decompressed_header->object_offset);
 2062|    153|	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|    153|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2070:6): [True: 0, False: 153]
  ------------------
 2071|    153|		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|    153|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2076:6): [True: 1, False: 152]
  ------------------
 2077|    153|		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|    152|	free(priv->token_name);
 2084|    152|	priv->token_name = malloc(decompressed_header->token_name_length+1);
 2085|    152|	if (priv->token_name == NULL) {
  ------------------
  |  Branch (2085:6): [True: 0, False: 152]
  ------------------
 2086|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2087|      0|		goto done;
 2088|      0|	}
 2089|    152|	memcpy(priv->token_name, &decompressed_header->token_name[0],
 2090|    152|							decompressed_header->token_name_length);
 2091|    152|	priv->token_name[decompressed_header->token_name_length] = '\0';
 2092|    152|	priv->token_name_length = decompressed_header->token_name_length;
 2093|       |
 2094|       |
 2095|    923|	for (i=0; i < object_count; i++) {
  ------------------
  |  Branch (2095:12): [True: 801, False: 122]
  ------------------
 2096|    801|		u8 *current_object = NULL;
 2097|    801|		coolkey_combined_object_header_t *object_header = NULL;
 2098|    801|		unsigned long object_id;
 2099|    801|		int current_object_len;
 2100|       |
 2101|       |		/* Can we read the object header at all? */
 2102|    801|		if ((object_offset + sizeof(coolkey_combined_object_header_t)) > decompressed_object_len) {
  ------------------
  |  Branch (2102:7): [True: 27, False: 774]
  ------------------
 2103|     27|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     27|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2104|     27|			goto done;
 2105|     27|		}
 2106|       |
 2107|    774|		current_object = &decompressed_object[object_offset];
 2108|    774|		object_header = (coolkey_combined_object_header_t *)current_object;
 2109|       |
 2110|       |		/* Parse object ID */
 2111|    774|		object_id = bebytes2ulong(object_header->object_id);
 2112|       |
 2113|       |		/* figure out how big it is */
 2114|    774|		r = coolkey_v1_get_object_length(current_object, decompressed_object_len-object_offset);
 2115|    774|		if (r < 0) {
  ------------------
  |  Branch (2115:7): [True: 0, False: 774]
  ------------------
 2116|      0|			goto done;
 2117|      0|		}
 2118|    774|		if ((size_t)r + object_offset > decompressed_object_len) {
  ------------------
  |  Branch (2118:7): [True: 0, False: 774]
  ------------------
 2119|      0|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2120|      0|			goto done;
 2121|      0|		}
 2122|    774|		current_object_len = r;
 2123|    774|		object_offset += current_object_len;
 2124|       |
 2125|       |		/* record this object */
 2126|    774|		sc_log(card->ctx, "Add new object id=%ld", object_id);
  ------------------
  |  |   71|    774|#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|    774|		r = coolkey_add_object(priv, object_id, current_object, current_object_len, 1);
 2128|    774|		if (r) {
  ------------------
  |  Branch (2128:7): [True: 3, False: 771]
  ------------------
 2129|      3|			goto done;
 2130|      3|		}
 2131|       |
 2132|    774|	}
 2133|    122|	r = SC_SUCCESS;
  ------------------
  |  |   28|    122|#define SC_SUCCESS				0
  ------------------
 2134|       |
 2135|    170|done:
 2136|    170|	if (free_decompressed) {
  ------------------
  |  Branch (2136:6): [True: 122, False: 48]
  ------------------
 2137|    122|		free(decompressed_object);
 2138|    122|	}
 2139|    170|	return r;
 2140|    122|}
card-coolkey.c:coolkey_v1_get_object_length:
  706|    774|{
  707|    774|	coolkey_combined_object_header_t *object_head = (coolkey_combined_object_header_t *) obj;
  708|    774|	int attribute_count;
  709|    774|	u8 *current_attribute;
  710|    774|	int j;
  711|    774|	size_t len;
  712|       |
  713|    774|	len = sizeof(coolkey_combined_object_header_t);
  714|    774|	if (buf_len <= len) {
  ------------------
  |  Branch (714:6): [True: 1, False: 773]
  ------------------
  715|      1|		return (int)buf_len;
  716|      1|	}
  717|    773|	attribute_count = bebytes2ushort(object_head->attribute_count);
  718|    773|	buf_len -= len;
  719|       |
  720|   113k|	for (current_attribute = obj + len, j = 0; j < attribute_count; j++) {
  ------------------
  |  Branch (720:45): [True: 113k, False: 773]
  ------------------
  721|   113k|		size_t attribute_len = coolkey_v1_get_attribute_record_len(current_attribute, buf_len);
  722|       |
  723|   113k|		len += attribute_len;
  724|   113k|		current_attribute += attribute_len;
  725|   113k|		buf_len -= attribute_len;
  726|   113k|	}
  727|    773|	return (int)len;
  728|    774|}
card-coolkey.c:coolkey_add_object:
 1972|  11.9k|{
 1973|  11.9k|	sc_cardctl_coolkey_object_t new_object;
 1974|  11.9k|	int r;
 1975|       |
 1976|  11.9k|	memset(&new_object, 0, sizeof(new_object));
 1977|  11.9k|	new_object.path = coolkey_template_path;
 1978|  11.9k|	new_object.path.len = 4;
 1979|  11.9k|	ulong2bebytes(new_object.path.value, object_id);
 1980|  11.9k|	new_object.id = object_id;
 1981|  11.9k|	new_object.length = object_length;
 1982|       |
 1983|       |	/* The object ID needs to be unique */
 1984|  11.9k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1984:6): [True: 3.32k, False: 8.61k]
  ------------------
 1985|  3.32k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  3.32k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1986|  3.32k|	}
 1987|       |
 1988|  8.61k|	if (object_data) {
  ------------------
  |  Branch (1988:6): [True: 771, False: 7.83k]
  ------------------
 1989|    771|		new_object.data = malloc(object_length + add_v1_record);
 1990|    771|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1990:7): [True: 0, False: 771]
  ------------------
 1991|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1992|      0|		}
 1993|    771|		if (add_v1_record) {
  ------------------
  |  Branch (1993:7): [True: 771, False: 0]
  ------------------
 1994|    771|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  229|    771|#define COOLKEY_V1_OBJECT 1
  ------------------
 1995|    771|			new_object.length++;
 1996|    771|		}
 1997|    771|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 1998|    771|	}
 1999|       |
 2000|  8.61k|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 2001|  8.61k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  8.61k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2001:6): [True: 0, False: 8.61k]
  ------------------
 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.61k|	return r;
 2008|  8.61k|}
card-coolkey.c:coolkey_add_object_to_list:
  816|  8.61k|{
  817|  8.61k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (817:6): [True: 0, False: 8.61k]
  ------------------
  818|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  819|  8.61k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.61k|#define SC_SUCCESS				0
  ------------------
  820|  8.61k|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1082|    562|{
 1083|    562|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1084|    562|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1085|    562|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1086|    562|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1087|    562|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1088|    562|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1089|    562|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1090|    562|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1091|    562|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1092|    562|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1093|    562|}
card-coolkey.c:coolkey_free_private_data:
  793|  1.09k|{
  794|  1.09k|	list_t *l = &priv->objects_list;
  795|  1.09k|	sc_cardctl_coolkey_object_t *o;
  796|       |
  797|       |	/* Clean up the allocated memory in the items */
  798|  1.09k|	list_iterator_start(l);
  799|  9.70k|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (799:9): [True: 8.61k, False: 1.09k]
  ------------------
  800|  8.61k|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  801|  8.61k|		free(o->data);
  802|  8.61k|		o->data = NULL;
  803|  8.61k|	}
  804|  1.09k|	list_iterator_stop(l);
  805|       |
  806|  1.09k|	list_destroy(&priv->objects_list);
  807|  1.09k|	free(priv->token_name);
  808|  1.09k|	free(priv);
  809|  1.09k|	return;
  810|  1.09k|}
card-coolkey.c:coolkey_finish:
 1960|    680|{
 1961|    680|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    680|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1962|       |
 1963|    680|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    680|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    680|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    680|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 680]
  |  |  ------------------
  ------------------
 1964|    680|	if (priv) {
  ------------------
  |  Branch (1964:6): [True: 680, False: 0]
  ------------------
 1965|    680|		coolkey_free_private_data(priv);
 1966|    680|	}
 1967|    680|	return SC_SUCCESS;
  ------------------
  |  |   28|    680|#define SC_SUCCESS				0
  ------------------
 1968|    680|}
card-coolkey.c:coolkey_select_file:
 1913|  2.65k|{
 1914|  2.65k|	int r;
 1915|  2.65k|	struct sc_file *file = NULL;
 1916|  2.65k|	coolkey_private_data_t *priv;
 1917|  2.65k|	unsigned long object_id;
 1918|       |
 1919|  2.65k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1919:6): [True: 0, False: 2.65k]
  |  Branch (1919:22): [True: 0, False: 2.65k]
  ------------------
 1920|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1921|       |
 1922|  2.65k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.65k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.65k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.65k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.65k]
  |  |  ------------------
  ------------------
 1923|       |
 1924|  2.65k|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  2.65k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1925|       |
 1926|  2.65k|	if (in_path->len != 4) {
  ------------------
  |  Branch (1926:6): [True: 1, False: 2.65k]
  ------------------
 1927|      1|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      1|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1928|      1|	}
 1929|  2.65k|	r = coolkey_select_applet(card);
 1930|  2.65k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.65k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1930:6): [True: 1.81k, False: 846]
  ------------------
 1931|  1.81k|		return r;
 1932|  1.81k|	}
 1933|    846|	object_id = bebytes2ulong(in_path->value);
 1934|    846|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1935|    846|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1935:6): [True: 543, False: 303]
  ------------------
 1936|    543|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    543|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1937|    543|	}
 1938|       |
 1939|    303|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|    303|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1940|    303|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  111|    303|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1940:6): [True: 270, False: 33]
  ------------------
 1941|    270|		priv->key_id = coolkey_get_key_id(object_id);
 1942|    270|	}
 1943|    303|	if (file_out) {
  ------------------
  |  Branch (1943:6): [True: 23, False: 280]
  ------------------
 1944|     23|		file = sc_file_new();
 1945|     23|		if (file == NULL)
  ------------------
  |  Branch (1945:7): [True: 0, False: 23]
  ------------------
 1946|     23|			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|     23|		file->path = *in_path;
 1948|       |		/* this could be like the FCI */
 1949|     23|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     23|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1950|     23|		file->shareable = 0;
 1951|     23|		file->ef_structure = 0;
 1952|     23|		file->size = priv->obj->length;
 1953|     23|		*file_out = file;
 1954|     23|	}
 1955|       |
 1956|    303|	return SC_SUCCESS;
  ------------------
  |  |   28|    303|#define SC_SUCCESS				0
  ------------------
 1957|    303|}
card-coolkey.c:coolkey_class:
 1886|    303|static u8 coolkey_class(unsigned long object_id) {
 1887|    303|	return (object_id >> 24) & 0xff;
 1888|    303|}
card-coolkey.c:coolkey_get_key_id:
 1890|    270|static unsigned short coolkey_get_key_id(unsigned long object_id) {
 1891|    270|	char char_index = (object_id >> 16) & 0xff;
 1892|    270|	if (char_index >= '0' && char_index <= '9') {
  ------------------
  |  Branch (1892:6): [True: 256, False: 14]
  |  Branch (1892:27): [True: 192, False: 64]
  ------------------
 1893|    192|		return (u8)(char_index - '0');
 1894|    192|	}
 1895|     78|	if (char_index >= 'A' && char_index <= 'Z') {
  ------------------
  |  Branch (1895:6): [True: 62, False: 16]
  |  Branch (1895:27): [True: 42, False: 20]
  ------------------
 1896|     42|		return (u8)(char_index - 'A' + 10);
 1897|     42|	}
 1898|     36|	if (char_index >= 'a' && char_index <= 'z') {
  ------------------
  |  Branch (1898:6): [True: 20, False: 16]
  |  Branch (1898:27): [True: 14, False: 6]
  ------------------
 1899|     14|		return (u8)(char_index - 'a' + 26 + 10);
 1900|     14|	}
 1901|     22|	return COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|     22|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1902|     36|}
card-coolkey.c:coolkey_read_binary:
 1184|    124|{
 1185|    124|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    124|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1186|    124|	int r = 0;
 1187|    124|	size_t len;
 1188|    124|	u8 *data = NULL;
 1189|       |
 1190|    124|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1191|    124|	if (idx > priv->obj->length) {
  ------------------
  |  Branch (1191:6): [True: 0, False: 124]
  ------------------
 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|    124|	if (priv->obj->data) {
  ------------------
  |  Branch (1196:6): [True: 101, False: 23]
  ------------------
 1197|    101|		sc_log(card->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__
  |  |  ------------------
  ------------------
 1198|    101|			 "returning cached value idx=%u count=%"SC_FORMAT_LEN_SIZE_T"u",
 1199|    101|			 idx, count);
 1200|    101|		len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|    101|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 92, False: 9]
  |  |  ------------------
  ------------------
 1201|    101|		memcpy(buf, &priv->obj->data[idx], len);
 1202|    101|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|    101|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    101|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    101|	int _ret = r; \
  |  |  |  |  155|    101|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 101]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    101|	} else { \
  |  |  |  |  159|    101|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    101|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    101|	} \
  |  |  |  |  162|    101|	return _ret; \
  |  |  |  |  163|    101|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1203|    101|	}
 1204|       |
 1205|     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__
  |  |  ------------------
  ------------------
 1206|     23|		 "clearing cache idx=%u count=%"SC_FORMAT_LEN_SIZE_T"u",
 1207|     23|		 idx, count);
 1208|       |
 1209|     23|	data = malloc(priv->obj->length);
 1210|     23|	if (data == NULL) {
  ------------------
  |  Branch (1210:6): [True: 0, False: 23]
  ------------------
 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|     23|	r = coolkey_read_object(card, priv->obj->id, 0, data, priv->obj->length,
 1217|     23|		priv->nonce, sizeof(priv->nonce));
 1218|     23|	if (r < 0)
  ------------------
  |  Branch (1218:6): [True: 10, False: 13]
  ------------------
 1219|     10|		goto done;
 1220|       |
 1221|     13|	if ((size_t) r != priv->obj->length) {
  ------------------
  |  Branch (1221:6): [True: 0, False: 13]
  ------------------
 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|     13|	len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|     13|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 9, False: 4]
  |  |  ------------------
  ------------------
 1228|     13|	memcpy(buf, &data[idx], len);
 1229|     13|	r = (int)len;
 1230|       |	/* cache the data in the object */
 1231|     13|	priv->obj->data=data;
 1232|     13|	data = NULL;
 1233|       |
 1234|     23|done:
 1235|     23|	if (data)
  ------------------
  |  Branch (1235:6): [True: 10, False: 13]
  ------------------
 1236|     10|		free(data);
 1237|     23|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     23|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     23|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     23|	int _ret = r; \
  |  |  |  |  155|     23|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 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|     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|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1238|     23|}
card-coolkey.c:coolkey_set_security_env:
 1634|    279|{
 1635|    279|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    279|#define SC_SUCCESS				0
  ------------------
 1636|    279|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    279|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1637|       |
 1638|    279|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    279|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    279|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    279|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 279]
  |  |  ------------------
  ------------------
 1639|       |
 1640|    279|	sc_log(card->ctx,
  ------------------
  |  |   71|    279|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1641|    279|		 "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%"SC_FORMAT_LEN_SIZE_T"u\n",
 1642|    279|		 env->flags, env->operation, env->algorithm,
 1643|    279|		 env->algorithm_flags, env->algorithm_ref, env->key_ref[0],
 1644|    279|		 env->key_ref_len);
 1645|       |
 1646|    279|	if ((env->algorithm != SC_ALGORITHM_RSA) && (env->algorithm != SC_ALGORITHM_EC)) {
  ------------------
  |  |   78|    279|#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: 279]
  |  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|    279|	priv->algorithm = env->algorithm;
 1650|    279|	priv->operation = env->operation;
 1651|       |
 1652|    279|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    279|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    279|	int _ret = r; \
  |  |  155|    279|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 279, False: 0]
  |  |  ------------------
  |  |  156|    279|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 279]
  |  |  ------------------
  |  |  157|    279|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    279|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    279|	return _ret; \
  |  |  163|    279|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1653|    279|}
card-coolkey.c:coolkey_compute_crypt:
 1865|    279|{
 1866|    279|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    279|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1867|    279|	int r;
 1868|    279|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    279|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    279|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    279|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 279]
  |  |  ------------------
  ------------------
 1869|       |
 1870|    279|	switch (priv->algorithm) {
 1871|    279|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|    279|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1871:2): [True: 279, False: 0]
  ------------------
 1872|    279|		r = coolkey_rsa_op(card, data, datalen, out, outlen);
 1873|    279|		break;
 1874|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1874:2): [True: 0, False: 279]
  ------------------
 1875|      0|		r = coolkey_ecc_op(card, data, datalen, out, outlen);
 1876|      0|		break;
 1877|      0|	default:
  ------------------
  |  Branch (1877:2): [True: 0, False: 279]
  ------------------
 1878|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 1879|      0|		break;
 1880|    279|	}
 1881|       |
 1882|    279|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    279|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    279|	int _ret = r; \
  |  |  155|    279|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 269, False: 10]
  |  |  ------------------
  |  |  156|    269|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    263|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 263, False: 6]
  |  |  ------------------
  |  |  157|    269|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    269|	} 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|    279|	return _ret; \
  |  |  163|    279|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1883|    279|}
card-coolkey.c:coolkey_rsa_op:
 1684|    279|{
 1685|    279|	int r;
 1686|    279|	u8 **crypt_out_p = NULL;
 1687|    279|	size_t crypt_out_len_p = 0;
 1688|    279|	coolkey_private_data_t *priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    279|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1689|    279|	coolkey_compute_crypt_params_t params;
 1690|    279|	u8 key_number;
 1691|    279|	size_t params_len;
 1692|    279|	u8 buf[MAX_COMPUTE_BUF + 2];
 1693|    279|	size_t buf_len;
 1694|    279|	u8 *buf_out;
 1695|       |
 1696|    279|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    279|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    279|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    279|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 279]
  |  |  ------------------
  ------------------
 1697|    279|	sc_log(card->ctx, "datalen=%"SC_FORMAT_LEN_SIZE_T"u outlen=%"SC_FORMAT_LEN_SIZE_T"u\n",
  ------------------
  |  |   71|    279|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1698|    279|		datalen, max_out_len);
 1699|       |
 1700|    279|	if (datalen > 0xFFFF) {
  ------------------
  |  Branch (1700:6): [True: 0, False: 279]
  ------------------
 1701|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1702|      0|		goto done;
 1703|      0|	}
 1704|       |
 1705|    279|	if (priv->key_id > 0xff) {
  ------------------
  |  Branch (1705:6): [True: 31, False: 248]
  ------------------
 1706|     31|		r = SC_ERROR_NO_DEFAULT_KEY;
  ------------------
  |  |  106|     31|#define SC_ERROR_NO_DEFAULT_KEY			-1504
  ------------------
 1707|     31|		goto done;
 1708|     31|	}
 1709|    248|	key_number = priv->key_id;
 1710|       |
 1711|    248|	memset(&params, 0, sizeof(params));
 1712|    248|	params.init.mode = COOLKEY_CRYPT_MODE_RSA_NO_PAD;
  ------------------
  |  |   98|    248|#define COOLKEY_CRYPT_MODE_RSA_NO_PAD    0x00
  ------------------
 1713|    248|	params.init.direction = COOLKEY_CRYPT_DIRECTION_ENCRYPT; /* for no pad, direction is irrelevant */
  ------------------
  |  |  101|    248|#define COOLKEY_CRYPT_DIRECTION_ENCRYPT  0x03
  ------------------
 1714|       |
 1715|       |	/* send the data to the card if necessary */
 1716|    248|	if (datalen > MAX_COMPUTE_BUF) {
  ------------------
  |  | 1663|    248|#define MAX_COMPUTE_BUF 200
  ------------------
  |  Branch (1716:6): [True: 118, False: 130]
  ------------------
 1717|       |		/* We need to write data to special object on the card as it does not safely fit APDU */
 1718|    118|		u8 len_buf[2];
 1719|       |
 1720|    118|		params.init.location = COOLKEY_CRYPT_LOCATION_DL_OBJECT;
  ------------------
  |  |  100|    118|#define COOLKEY_CRYPT_LOCATION_DL_OBJECT 0x02
  ------------------
 1721|       |
 1722|    118|		params_len = sizeof(params.init);
 1723|       |
 1724|    118|		ushort2bebytes(len_buf, datalen);
 1725|       |
 1726|    118|		r = coolkey_write_object(card, COOLKEY_DL_OBJECT_ID, 0, len_buf, sizeof(len_buf),
  ------------------
  |  |  108|    118|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1727|    118|					priv->nonce, sizeof(priv->nonce));
 1728|    118|		if (r < 0) {
  ------------------
  |  Branch (1728:7): [True: 22, False: 96]
  ------------------
 1729|     22|			goto done;
 1730|     22|		}
 1731|       |
 1732|     96|		r = coolkey_write_object(card, COOLKEY_DL_OBJECT_ID, 2, data, datalen, priv->nonce, sizeof(priv->nonce));
  ------------------
  |  |  108|     96|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1733|     96|		if (r < 0) {
  ------------------
  |  Branch (1733:7): [True: 43, False: 53]
  ------------------
 1734|     43|			goto done;
 1735|     43|		}
 1736|     53|		ushort2bebytes(params.init.buf_len, 0);
 1737|    130|	} else {
 1738|       |		/* The data fits in APDU. Copy it to the params object */
 1739|    130|		params.init.location = COOLKEY_CRYPT_LOCATION_APDU;
  ------------------
  |  |   99|    130|#define COOLKEY_CRYPT_LOCATION_APDU      0x01
  ------------------
 1740|       |
 1741|    130|		params_len = sizeof(params.init) + datalen;
 1742|       |
 1743|    130|		buf_out = &buf[0];
 1744|    130|		crypt_out_p = &buf_out;
 1745|    130|		buf_len = sizeof(buf);
 1746|    130|		crypt_out_len_p = buf_len;
 1747|       |
 1748|    130|		ushort2bebytes(params.init.buf_len, datalen);
 1749|    130|		memcpy(params.buf, data, datalen);
 1750|    130|	}
 1751|       |
 1752|    183|	r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_COMPUTE_CRYPT,
  ------------------
  |  |   72|    183|#define COOLKEY_CLASS           0xb0
  ------------------
              	r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_COMPUTE_CRYPT,
  ------------------
  |  |   84|    183|#define COOLKEY_INS_COMPUTE_CRYPT              0x36
  ------------------
 1753|    183|			key_number, COOLKEY_CRYPT_ONE_STEP, (u8 *)&params, params_len,
  ------------------
  |  |   96|    183|#define COOLKEY_CRYPT_ONE_STEP 4
  ------------------
 1754|    183|			crypt_out_p, &crypt_out_len_p, priv->nonce, sizeof(priv->nonce));
 1755|    183|	if (r < 0) {
  ------------------
  |  Branch (1755:6): [True: 36, False: 147]
  ------------------
 1756|     36|		goto done;
 1757|     36|	}
 1758|    147|	buf_len = crypt_out_len_p;
 1759|       |
 1760|    147|	if (datalen > MAX_COMPUTE_BUF) {
  ------------------
  |  | 1663|    147|#define MAX_COMPUTE_BUF 200
  ------------------
  |  Branch (1760:6): [True: 49, False: 98]
  ------------------
 1761|     49|		u8 len_buf[2];
 1762|     49|		size_t out_length;
 1763|       |
 1764|     49|		r = coolkey_read_object(card, COOLKEY_DL_OBJECT_ID, 0, len_buf, sizeof(len_buf),
  ------------------
  |  |  108|     49|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1765|     49|					priv->nonce, sizeof(priv->nonce));
 1766|     49|		if (r < 0) {
  ------------------
  |  Branch (1766:7): [True: 26, False: 23]
  ------------------
 1767|     26|			goto done;
 1768|     26|		}
 1769|       |
 1770|     23|		out_length = bebytes2ushort(len_buf);
 1771|     23|		out_length = MIN(out_length,max_out_len);
  ------------------
  |  |   70|     23|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 22, False: 1]
  |  |  ------------------
  ------------------
 1772|       |
 1773|     23|		r = coolkey_read_object(card, COOLKEY_DL_OBJECT_ID, sizeof(len_buf), out, out_length,
  ------------------
  |  |  108|     23|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1774|     23|					priv->nonce, sizeof(priv->nonce));
 1775|       |
 1776|     98|	} else {
 1777|     98|		size_t out_length;
 1778|     98|		if (buf_len < 2) {
  ------------------
  |  Branch (1778:7): [True: 40, False: 58]
  ------------------
 1779|     40|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     40|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1780|     40|			goto done;
 1781|     40|		}
 1782|     58|		out_length = bebytes2ushort(buf);
 1783|     58|		if (out_length > (buf_len - 2)) {
  ------------------
  |  Branch (1783:7): [True: 49, False: 9]
  ------------------
 1784|     49|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     49|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1785|     49|			goto done;
 1786|     49|		}
 1787|      9|		out_length = MIN(out_length, max_out_len);
  ------------------
  |  |   70|      9|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 9, False: 0]
  |  |  ------------------
  ------------------
 1788|      9|		memcpy(out, buf + 2, out_length);
 1789|      9|		r = (int)out_length;
 1790|      9|	}
 1791|       |
 1792|    279|done:
 1793|    279|	return r;
 1794|    147|}
card-coolkey.c:coolkey_write_object:
 1143|    214|{
 1144|    214|	coolkey_write_object_param_t params;
 1145|    214|	size_t operation_len;
 1146|    214|	size_t left = buf_len;
 1147|    214|	int r;
 1148|    214|	size_t max_operation_len;
 1149|       |
 1150|       |	/* set limit for the card's maximum send size and short write */
 1151|    214|	max_operation_len = MIN(COOLKEY_MAX_CHUNK_SIZE, (card->max_send_size - sizeof(coolkey_read_object_param_t) - nonce_size));
  ------------------
  |  |   70|    214|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 214]
  |  |  ------------------
  ------------------
 1152|       |
 1153|    214|	ulong2bebytes(&params.head.object_id[0], object_id);
 1154|       |
 1155|  1.85k|	do {
 1156|  1.85k|		ulong2bebytes(&params.head.offset[0], offset);
 1157|  1.85k|		operation_len = MIN(left, max_operation_len);
  ------------------
  |  |   70|  1.85k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 180, False: 1.67k]
  |  |  ------------------
  ------------------
 1158|  1.85k|		params.head.length = operation_len;
 1159|  1.85k|		memcpy(params.buf, buf, operation_len);
 1160|  1.85k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
  ------------------
  |  |   72|  1.85k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
  ------------------
  |  |   89|  1.85k|#define COOLKEY_INS_WRITE_OBJECT               0x54
  ------------------
 1161|  1.85k|			(u8 *)&params, sizeof(params.head)+operation_len, NULL, 0, nonce, nonce_size);
 1162|  1.85k|		if (r < 0) {
  ------------------
  |  Branch (1162:7): [True: 65, False: 1.78k]
  ------------------
 1163|     65|			goto fail;
 1164|     65|		}
 1165|  1.78k|		buf += operation_len;
 1166|  1.78k|		offset += operation_len;
 1167|  1.78k|		left -= operation_len;
 1168|  1.78k|	} while (left != 0);
  ------------------
  |  Branch (1168:11): [True: 1.63k, False: 149]
  ------------------
 1169|       |
 1170|    149|	return (int)(buf_len - left);
 1171|       |
 1172|     65|fail:
 1173|     65|	return r;
 1174|    214|}
card-coolkey.c:coolkey_card_ctl:
 1589|  68.0k|{
 1590|  68.0k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  68.0k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1591|       |
 1592|  68.0k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  68.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  68.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  68.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  68.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 68.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1593|  68.0k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  68.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__
  |  |  ------------------
  ------------------
 1594|       |
 1595|  68.0k|	if (priv == NULL) {
  ------------------
  |  Branch (1595:6): [True: 0, False: 68.0k]
  ------------------
 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|  68.0k|	switch(cmd) {
  ------------------
  |  Branch (1598:9): [True: 68.0k, False: 0]
  ------------------
 1599|      0|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1599:3): [True: 0, False: 68.0k]
  ------------------
 1600|      0|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1601|    680|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1601:3): [True: 680, False: 67.3k]
  ------------------
 1602|    680|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1603|  2.03k|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1603:3): [True: 2.03k, False: 66.0k]
  ------------------
 1604|  2.03k|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1605|    680|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1605:3): [True: 680, False: 67.3k]
  ------------------
 1606|    680|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1607|  7.50k|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1607:3): [True: 7.50k, False: 60.5k]
  ------------------
 1608|  7.50k|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1609|    680|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1609:3): [True: 680, False: 67.3k]
  ------------------
 1610|    680|			return coolkey_final_iterator(&priv->objects_list);
 1611|  56.4k|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1611:3): [True: 56.4k, False: 11.5k]
  ------------------
 1612|  56.4k|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1613|  68.0k|	}
 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|    680|{
 1335|    680|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    680|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1336|    680|	char *label = NULL;
 1337|    680|	char *manufacturer_id = NULL;
 1338|    680|	char *serial_number = NULL;
 1339|       |
 1340|    680|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    680|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    680|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    680|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    680|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 680]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|    680|	label = strdup((char *)priv->token_name);
 1342|    680|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1343|    680|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1344|       |
 1345|    680|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1345:6): [True: 680, False: 0]
  |  Branch (1345:15): [True: 680, False: 0]
  |  Branch (1345:34): [True: 680, False: 0]
  ------------------
 1346|    680|		free(token_info->label);
 1347|    680|		token_info->label = label;
 1348|    680|		free(token_info->manufacturer_id);
 1349|    680|		token_info->manufacturer_id = manufacturer_id;
 1350|    680|		free(token_info->serial_number);
 1351|    680|		token_info->serial_number = serial_number;
 1352|    680|		return SC_SUCCESS;
  ------------------
  |  |   28|    680|#define SC_SUCCESS				0
  ------------------
 1353|    680|	}
 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|    680|}
card-coolkey.c:coolkey_get_manufacturer:
 1305|    680|{
 1306|    680|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1307|    680|	int i;
 1308|    680|	char *buf;
 1309|    680|	const char *manufacturer_string = "%04x Unknown";
 1310|    680|	size_t len;
 1311|    680|	int r;
 1312|       |
 1313|  4.05k|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1313:12): [True: 3.39k, False: 658]
  ------------------
 1314|  3.39k|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1314:7): [True: 22, False: 3.37k]
  ------------------
 1315|     22|			manufacturer_string = manufacturer_list[i].string;
 1316|     22|			break;
 1317|     22|		}
 1318|  3.39k|	}
 1319|    680|	len = strlen(manufacturer_string)+1;
 1320|    680|	buf= malloc(len);
 1321|    680|	if (buf == NULL) {
  ------------------
  |  Branch (1321:6): [True: 0, False: 680]
  ------------------
 1322|      0|		return NULL;
 1323|      0|	}
 1324|    680|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1325|    680|	if (r < 0) {
  ------------------
  |  Branch (1325:6): [True: 0, False: 680]
  ------------------
 1326|      0|		free(buf);
 1327|      0|		return NULL;
 1328|      0|	}
 1329|    680|	return buf;
 1330|    680|}
card-coolkey.c:coolkey_cuid_to_string:
 1280|    680|{
 1281|    680|	char *buf;
 1282|    680|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1283|    680|	buf = malloc(len);
 1284|    680|	if (buf == NULL) {
  ------------------
  |  Branch (1284:6): [True: 0, False: 680]
  ------------------
 1285|      0|		return NULL;
 1286|      0|	}
 1287|    680|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1288|    680|	return buf;
 1289|    680|}
card-coolkey.c:coolkey_find_object:
 1560|  2.03k|{
 1561|  2.03k|	sc_cardctl_coolkey_object_t *obj = NULL;
 1562|  2.03k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  2.03k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1563|  2.03k|	int r;
 1564|       |
 1565|  2.03k|	switch (fobj->type) {
 1566|    399|	case SC_CARDCTL_COOLKEY_FIND_BY_ID:
  ------------------
  |  | 1059|    399|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
  |  Branch (1566:2): [True: 399, False: 1.63k]
  ------------------
 1567|    399|		obj = coolkey_find_object_by_id(&priv->objects_list, fobj->find_id);
 1568|    399|		break;
 1569|  1.63k|	case SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE:
  ------------------
  |  | 1060|  1.63k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  |  Branch (1569:2): [True: 1.63k, False: 399]
  ------------------
 1570|  1.63k|		obj = coolkey_find_object_by_template(card, fobj->coolkey_template, fobj->template_count);
 1571|  1.63k|		break;
 1572|      0|	default:
  ------------------
  |  Branch (1572:2): [True: 0, False: 2.03k]
  ------------------
 1573|      0|		break;
 1574|  2.03k|	}
 1575|  2.03k|	if (obj == NULL) {
  ------------------
  |  Branch (1575:6): [True: 882, False: 1.15k]
  ------------------
 1576|    882|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    882|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 1577|    882|	}
 1578|  1.15k|	if (obj->data == NULL) {
  ------------------
  |  Branch (1578:6): [True: 77, False: 1.07k]
  ------------------
 1579|     77|		r = coolkey_fill_object(card, obj);
 1580|     77|		if (r < 0) {
  ------------------
  |  Branch (1580:7): [True: 61, False: 16]
  ------------------
 1581|     61|			return r;
 1582|     61|		}
 1583|     77|	}
 1584|  1.09k|	fobj->obj = obj;
 1585|  1.09k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.09k|#define SC_SUCCESS				0
  ------------------
 1586|  1.15k|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1253|    680|{
 1254|    680|	*countp = list_size(list);
 1255|    680|	list_iterator_start(list);
 1256|    680|	return SC_SUCCESS;
  ------------------
  |  |   28|    680|#define SC_SUCCESS				0
  ------------------
 1257|    680|}
card-coolkey.c:coolkey_fetch_object:
 1261|  7.50k|{
 1262|  7.50k|	sc_cardctl_coolkey_object_t *ptr;
 1263|  7.50k|	if (!list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1263:6): [True: 0, False: 7.50k]
  ------------------
 1264|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
 1265|      0|	}
 1266|       |
 1267|  7.50k|	ptr = list_iterator_next(list);
 1268|  7.50k|	*coolkey_obj = *ptr;
 1269|  7.50k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.50k|#define SC_SUCCESS				0
  ------------------
 1270|  7.50k|}
card-coolkey.c:coolkey_final_iterator:
 1274|    680|{
 1275|    680|	list_iterator_stop(list);
 1276|    680|	return SC_SUCCESS;
  ------------------
  |  |   28|    680|#define SC_SUCCESS				0
  ------------------
 1277|    680|}
card-coolkey.c:coolkey_check_sw:
  876|  74.4k|{
  877|  74.4k|	sc_log(card->ctx,
  ------------------
  |  |   71|  74.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|  74.4k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  879|       |
  880|  74.4k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (880:6): [True: 36.1k, False: 38.2k]
  |  Branch (880:21): [True: 34.2k, False: 1.91k]
  ------------------
  881|  34.2k|		return SC_SUCCESS;
  ------------------
  |  |   28|  34.2k|#define SC_SUCCESS				0
  ------------------
  882|       |
  883|  40.2k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (883:6): [True: 1.05k, False: 39.1k]
  ------------------
  884|  1.05k|		if (sw2 == 0xff) {
  ------------------
  |  Branch (884:7): [True: 22, False: 1.03k]
  ------------------
  885|       |			/* shouldn't happen on a production applet, 0x9cff is a debugging error code */
  886|     22|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     22|#define SC_ERROR_INTERNAL			-1400
  ------------------
  887|     22|		}
  888|  1.03k|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (888:7): [True: 67, False: 967]
  ------------------
  889|     67|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     67|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  890|     67|		}
  891|    967|		return coolkey_error_codes[sw2].sc_error;
  892|  1.03k|	}
  893|       |
  894|       |	/* iso error */
  895|  39.1k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  896|  40.2k|}
card-coolkey.c:coolkey_pin_cmd:
 2358|    723|{
 2359|    723|	int r;
 2360|    723|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    723|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2361|    723|	size_t rbuflen;
 2362|    723|	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|    723|	switch (data->cmd) {
 2370|    680|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|    680|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2370:2): [True: 680, False: 43]
  ------------------
 2371|    680|		if (priv->nonce_valid) {
  ------------------
  |  Branch (2371:7): [True: 6, False: 674]
  ------------------
 2372|      6|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|      6|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 2373|    674|		} else {
 2374|    674|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|    674|#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|    674|			data->pin1.tries_left = 0xf;
 2379|    674|		}
 2380|    680|		r = SC_SUCCESS;
  ------------------
  |  |   28|    680|#define SC_SUCCESS				0
  ------------------
 2381|    680|		break;
 2382|       |
 2383|     12|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|     12|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2383:2): [True: 12, False: 711]
  ------------------
 2384|     24|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|     24|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2384:2): [True: 12, False: 711]
  ------------------
 2385|       |		/* these 2 commands are currently reserved for TPS */
 2386|     24|	default:
  ------------------
  |  Branch (2386:2): [True: 0, False: 723]
  ------------------
 2387|     24|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     24|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2388|     24|		break;
 2389|     19|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|     19|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2389:2): [True: 19, False: 704]
  ------------------
 2390|       |		/* coolkey applet supports multiple pins, but TPS currently only uses one.
 2391|       |		 * just support the one pin for now (we need an array of nonces to handle
 2392|       |		 * multiple pins) */
 2393|       |		/* coolkey only supports unpadded ascii pins, so no need to format the pin */
 2394|     19|		rbuflen = sizeof(priv->nonce);
 2395|     19|		rbuf = &priv->nonce[0];
 2396|     19|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   72|     19|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   80|     19|#define COOLKEY_INS_VERIFY_PIN                 0x42
  ------------------
 2397|     19|			data->pin_reference, 0, data->pin1.data, data->pin1.len,
 2398|     19|			&rbuf, &rbuflen, NULL, 0);
 2399|     19|		if (r < 0) {
  ------------------
  |  Branch (2399:7): [True: 13, False: 6]
  ------------------
 2400|     13|			break;
 2401|     13|		}
 2402|      6|		priv->nonce_valid = 1;
 2403|      6|		r = SC_SUCCESS;
  ------------------
  |  |   28|      6|#define SC_SUCCESS				0
  ------------------
 2404|    723|	}
 2405|    723|	return r;
 2406|    723|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2427|  27.1k|{
 2428|  27.1k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  27.1k|#define SC_SUCCESS				0
  ------------------
 2429|       |
 2430|  27.1k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  27.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  27.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  27.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 27.1k]
  |  |  ------------------
  ------------------
 2431|       |
 2432|  27.1k|	if (was_reset > 0) {
  ------------------
  |  Branch (2432:6): [True: 0, False: 27.1k]
  ------------------
 2433|      0|		r = coolkey_select_applet(card);
 2434|      0|	}
 2435|       |
 2436|  27.1k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  27.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  27.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  27.1k|	int _ret = r; \
  |  |  |  |  155|  27.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 27.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  27.1k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 27.1k]
  |  |  |  |  ------------------
  |  |  |  |  157|  27.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  27.1k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  27.1k|	return _ret; \
  |  |  |  |  163|  27.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2437|  27.1k|}

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

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

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

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

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

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

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

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

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

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

sc_get_gids_driver:
 2196|  16.4k|{
 2197|  16.4k|	return sc_get_driver();
 2198|  16.4k|}
card-gids.c:sc_get_driver:
 2151|  16.4k|{
 2152|       |
 2153|  16.4k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2153:6): [True: 1, False: 16.4k]
  ------------------
 2154|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2155|       |
 2156|  16.4k|	gids_ops.match_card = gids_match_card;
 2157|  16.4k|	gids_ops.init = gids_init;
 2158|  16.4k|	gids_ops.finish = gids_finish;
 2159|  16.4k|	gids_ops.read_binary = gids_read_binary;
 2160|  16.4k|	gids_ops.write_binary = NULL;
 2161|  16.4k|	gids_ops.update_binary = NULL;
 2162|  16.4k|	gids_ops.erase_binary = NULL;
 2163|  16.4k|	gids_ops.read_record = NULL;
 2164|  16.4k|	gids_ops.write_record = NULL;
 2165|  16.4k|	gids_ops.append_record = NULL;
 2166|  16.4k|	gids_ops.update_record = NULL;
 2167|  16.4k|	gids_ops.select_file = gids_select_file;
 2168|  16.4k|	gids_ops.get_response = iso_ops->get_response;
 2169|  16.4k|	gids_ops.get_challenge = NULL;
 2170|  16.4k|	gids_ops.verify = NULL; // see pin_cmd
 2171|  16.4k|	gids_ops.logout = gids_logout;
 2172|  16.4k|	gids_ops.restore_security_env = NULL;
 2173|  16.4k|	gids_ops.set_security_env = gids_set_security_env;
 2174|  16.4k|	gids_ops.decipher = gids_decipher;
 2175|  16.4k|	gids_ops.compute_signature = iso_ops->compute_signature;
 2176|  16.4k|	gids_ops.change_reference_data = NULL; // see pin_cmd
 2177|  16.4k|	gids_ops.reset_retry_counter = NULL; // see pin_cmd
 2178|  16.4k|	gids_ops.create_file = iso_ops->create_file;
 2179|  16.4k|	gids_ops.delete_file = NULL;
 2180|  16.4k|	gids_ops.list_files = NULL;
 2181|  16.4k|	gids_ops.check_sw = iso_ops->check_sw;
 2182|  16.4k|	gids_ops.card_ctl = gids_card_ctl;
 2183|  16.4k|	gids_ops.process_fci = iso_ops->process_fci;
 2184|  16.4k|	gids_ops.construct_fci = iso_ops->construct_fci;
 2185|  16.4k|	gids_ops.pin_cmd = gids_pin_cmd;
 2186|  16.4k|	gids_ops.get_data = NULL;
 2187|  16.4k|	gids_ops.put_data = NULL;
 2188|  16.4k|	gids_ops.delete_record = NULL;
 2189|  16.4k|	gids_ops.read_public_key = gids_read_public_key;
 2190|  16.4k|	gids_ops.card_reader_lock_obtained = gids_card_reader_lock_obtained;
 2191|       |
 2192|  16.4k|	return &gids_drv;
 2193|  16.4k|}
card-gids.c:gids_match_card:
  567|  3.55k|{
  568|  3.55k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  569|  3.55k|	int r,i;
  570|  3.55k|	size_t resplen = sizeof(rbuf);
  571|  3.55k|	const u8 *tag;
  572|  3.55k|	size_t taglen;
  573|  3.55k|	const u8 *aid;
  574|  3.55k|	size_t aidlen;
  575|       |
  576|  3.55k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.55k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.55k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.55k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.55k]
  |  |  ------------------
  ------------------
  577|       |
  578|       |	/* Detect by selecting applet */
  579|  3.55k|	r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
  580|  3.55k|	if (r<0) return 0;
  ------------------
  |  Branch (580:6): [True: 3.42k, False: 132]
  ------------------
  581|       |
  582|    132|	card->type = SC_CARD_TYPE_GIDS_GENERIC;
  583|    132|	if (resplen > 2) {
  ------------------
  |  Branch (583:6): [True: 17, False: 115]
  ------------------
  584|     17|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, GIDS_APPLICATION_TEMPLATE_TAG, &taglen);
  ------------------
  |  |  105|     17|#define GIDS_APPLICATION_TEMPLATE_TAG 0x61
  ------------------
  585|     17|		if (tag != NULL) {
  ------------------
  |  Branch (585:7): [True: 14, False: 3]
  ------------------
  586|     14|			aid = sc_asn1_find_tag(card->ctx, tag, taglen, GIDS_APPLICATION_AID_TAG, &aidlen);
  ------------------
  |  |  106|     14|#define GIDS_APPLICATION_AID_TAG 0x4F
  ------------------
  587|     14|			if (aid != NULL ) {
  ------------------
  |  Branch (587:8): [True: 13, False: 1]
  ------------------
  588|     13|				sc_log(card->ctx, "found AID");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  589|     36|				for (i = 0; gids_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (589:17): [True: 25, False: 11]
  ------------------
  590|     25|					if ( aidlen > gids_aids[i].len_long && memcmp(aid, gids_aids[i].value,
  ------------------
  |  Branch (590:11): [True: 23, False: 2]
  |  Branch (590:45): [True: 2, False: 21]
  ------------------
  591|     23|									gids_aids[i].len_long) == 0) {
  592|      2|						card->type = gids_aids[i].enumtag;
  593|      2|						break;
  594|      2|					}
  595|     25|				}
  596|     13|			}
  597|     14|		}
  598|     17|	}
  599|       |
  600|    132|	return 1;
  601|  3.55k|}
card-gids.c:gids_select_aid:
  283|  3.55k|{
  284|  3.55k|	sc_apdu_t apdu;
  285|  3.55k|	int r;
  286|       |
  287|  3.55k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.55k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.55k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.55k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.55k]
  |  |  ------------------
  ------------------
  288|  3.55k|	sc_log(card->ctx,
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 3.55k, False: 0]
  |  |  ------------------
  ------------------
  289|  3.55k|		 "Got args: aid=%p, aidlen=%"SC_FORMAT_LEN_SIZE_T"u, response=%p, responselen=%"SC_FORMAT_LEN_SIZE_T"u\n",
  290|  3.55k|		 aid, aidlen, response, responselen ? *responselen : 0);
  291|       |
  292|  3.55k|	sc_format_apdu(card, &apdu,
  293|  3.55k|		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.55k|#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.55k|#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.55k|#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.55k|#define P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00
  ------------------
  |  Branch (293:3): [True: 0, False: 3.55k]
  ------------------
  294|  3.55k|	apdu.lc = aidlen;
  295|  3.55k|	apdu.data = aid;
  296|  3.55k|	apdu.datalen = aidlen;
  297|  3.55k|	apdu.resp = response;
  298|  3.55k|	apdu.resplen = responselen ? *responselen : 0;
  ------------------
  |  Branch (298:17): [True: 3.55k, False: 0]
  ------------------
  299|  3.55k|	apdu.le = response == NULL ? 0 : 256; /* could be 21 for fci */
  ------------------
  |  Branch (299:12): [True: 0, False: 3.55k]
  ------------------
  300|       |
  301|  3.55k|	r = sc_transmit_apdu(card, &apdu);
  302|  3.55k|	if (responselen)
  ------------------
  |  Branch (302:6): [True: 3.55k, False: 0]
  ------------------
  303|  3.55k|		*responselen = apdu.resplen;
  304|  3.55k|	LOG_TEST_RET(card->ctx, r, "gids select failed");
  ------------------
  |  |  174|  3.55k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.55k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.55k|	int _ret = (r); \
  |  |  |  |  168|  3.55k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 3.54k]
  |  |  |  |  ------------------
  |  |  |  |  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|  3.55k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.54k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|  3.54k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  3.54k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.54k|	int _ret = r; \
  |  |  155|  3.54k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.54k, False: 0]
  |  |  ------------------
  |  |  156|  3.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|  3.41k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3.41k, False: 132]
  |  |  ------------------
  |  |  157|  3.54k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.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|  3.54k|	return _ret; \
  |  |  163|  3.54k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  306|  3.54k|}
card-gids.c:gids_init:
  635|    132|{
  636|    132|	unsigned long flags;
  637|    132|	struct gids_private_data *data;
  638|    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]
  |  |  ------------------
  ------------------
  639|       |
  640|       |	// cache some data in memory
  641|    132|	data = (struct gids_private_data*) calloc(1, sizeof(struct gids_private_data));
  642|    132|	if (!data) {
  ------------------
  |  Branch (642:6): [True: 0, False: 132]
  ------------------
  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|    132|	memset(data, 0, sizeof(struct gids_private_data));
  646|    132|	card->drv_data = data;
  647|       |	// invalidate the master file and cmap file cache
  648|    132|	data->cmapfilesize = sizeof(data->cmapfile);
  649|    132|	data->masterfilesize = sizeof(data->masterfile);
  650|       |
  651|       |	/* supported RSA keys and how padding is done */
  652|    132|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  120|    132|#define SC_ALGORITHM_RSA_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|    132|#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|    132|#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|    132|#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|    132|#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|    132|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  656|    132|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  657|    132|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
  658|    132|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  659|       |
  660|    132|	return SC_SUCCESS;
  ------------------
  |  |   28|    132|#define SC_SUCCESS				0
  ------------------
  661|    132|}
card-gids.c:gids_finish:
  665|    132|{
  666|    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]
  |  |  ------------------
  ------------------
  667|       |	/* free the private data */
  668|    132|	if (card->drv_data) {
  ------------------
  |  Branch (668:6): [True: 132, False: 0]
  ------------------
  669|    132|		free(card->drv_data);
  670|       |		card->drv_data = NULL;
  671|    132|	}
  672|    132|	return 0;
  673|    132|}
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|    145|static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdentifier, u8* response, size_t *responselen) {
  211|    145|	sc_apdu_t apdu;
  212|    145|	int r;
  213|    145|	u8 data[4] = {0x5C, 0x02, (dataObjectIdentifier&0xFF00)>>8, (dataObjectIdentifier&0xFF)};
  214|    145|	size_t datasize = 0;
  215|    145|	const u8* p;
  216|    145|	u8 buffer[MAX_GIDS_FILE_SIZE];
  217|    145|	size_t buffer_len = sizeof(buffer);
  218|       |
  219|    145|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    145|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    145|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    145|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 145]
  |  |  ------------------
  ------------------
  220|    145|	sc_log(card->ctx,
  ------------------
  |  |   71|    290|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 145, False: 0]
  |  |  ------------------
  ------------------
  221|    145|		 "Got args: fileIdentifier=%x, dataObjectIdentifier=%x, response=%p, responselen=%"SC_FORMAT_LEN_SIZE_T"u\n",
  222|    145|		 fileIdentifier, dataObjectIdentifier, response,
  223|    145|		 responselen ? *responselen : 0);
  224|       |
  225|    145|	sc_format_apdu(card, &apdu,
  226|    145|		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|    145|#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|    145|#define INS_GET_DATA 0xCB
  ------------------
  |  Branch (226:3): [True: 0, False: 145]
  ------------------
  227|    145|	apdu.lc = 04;
  228|    145|	apdu.data = data;
  229|    145|	apdu.datalen = 04;
  230|    145|	apdu.resp = buffer;
  231|    145|	apdu.resplen = buffer_len;
  232|    145|	apdu.le = 256;
  233|       |
  234|    145|	r = sc_transmit_apdu(card, &apdu);
  235|    145|	LOG_TEST_RET(card->ctx, r, "gids get data failed");
  ------------------
  |  |  174|    145|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    145|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    145|	int _ret = (r); \
  |  |  |  |  168|    145|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 142]
  |  |  |  |  ------------------
  |  |  |  |  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|    145|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 142]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|    142|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
  ------------------
  |  |  174|    142|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    142|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    142|	int _ret = (r); \
  |  |  |  |  168|    142|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 33, False: 109]
  |  |  |  |  ------------------
  |  |  |  |  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|    142|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 109]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  237|    109|	buffer_len = apdu.resplen;
  238|       |
  239|    109|	p = sc_asn1_find_tag(card->ctx, buffer, buffer_len, dataObjectIdentifier, &datasize);
  240|    109|	if (!p) {
  ------------------
  |  Branch (240:6): [True: 5, False: 104]
  ------------------
  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|    104|	if (response && responselen) {
  ------------------
  |  Branch (243:6): [True: 104, False: 0]
  |  Branch (243:18): [True: 104, False: 0]
  ------------------
  244|    104|		if (datasize > *responselen) {
  ------------------
  |  Branch (244:7): [True: 0, False: 104]
  ------------------
  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|    104|		memcpy(response, p, datasize);
  248|    104|		*responselen = datasize;
  249|    104|	}
  250|    104|	return SC_SUCCESS;
  ------------------
  |  |   28|    104|#define SC_SUCCESS				0
  ------------------
  251|    104|}
card-gids.c:gids_select_file:
  971|    672|			   struct sc_file **file_out) {
  972|    672|	struct sc_file *file = NULL;
  973|    672|	struct sc_context *ctx = card->ctx;
  974|    672|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
  975|       |
  976|    672|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    672|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    672|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    672|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    672|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 672]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  977|       |
  978|    672|	data->state = GIDS_STATE_NONE;
  ------------------
  |  |   57|    672|#define GIDS_STATE_NONE 0
  ------------------
  979|    672|	data->currentDO = 0;
  980|    672|	data->currentEFID = 0;
  981|    672|	if (in_path->len == 4 && in_path->value[0] == 0xA0) {
  ------------------
  |  Branch (981:6): [True: 386, False: 286]
  |  Branch (981:27): [True: 0, False: 386]
  ------------------
  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|    672|	} 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: 386, False: 286]
  |  Branch (998:34): [True: 386, False: 0]
  |  Branch (998:63): [True: 0, False: 386]
  |  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|    672|	} else {
 1009|    672|		return iso_ops->select_file(card, in_path, file_out);
 1010|    672|	}
 1011|    672|}
card-gids.c:gids_card_ctl:
 2100|    144|{
 2101|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2102|    144|	switch (cmd) {
 2103|     13|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2103:3): [True: 13, False: 131]
  ------------------
 2104|     13|			return gids_get_serialnr(card, (sc_serial_number_t *) ptr);
 2105|    131|		case SC_CARDCTL_GIDS_GET_ALL_CONTAINERS:
  ------------------
  |  Branch (2105:3): [True: 131, False: 13]
  ------------------
 2106|    131|			return gids_get_all_containers(card, (size_t*) ptr);
 2107|      0|		case SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL:
  ------------------
  |  Branch (2107:3): [True: 0, False: 144]
  ------------------
 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: 144]
  ------------------
 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: 144]
  ------------------
 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: 144]
  ------------------
 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: 144]
  ------------------
 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: 144]
  ------------------
 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: 144]
  ------------------
 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: 144]
  ------------------
 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: 144]
  ------------------
 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: 144]
  ------------------
 2127|      0|			return gids_set_administrator_key(card, (u8*) ptr);
 2128|      0|		case SC_CARDCTL_GIDS_AUTHENTICATE_ADMIN:
  ------------------
  |  Branch (2128:3): [True: 0, False: 144]
  ------------------
 2129|      0|			return gids_authenticate_admin(card, (u8*) ptr);
 2130|      0|		default:
  ------------------
  |  Branch (2130:3): [True: 0, False: 144]
  ------------------
 2131|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2132|    144|	}
 2133|    144|}
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|    104|static int gids_read_gidsfile(sc_card_t* card, char *directory, char *filename, u8* response, size_t *responselen) {
  390|    104|	struct gids_private_data* privatedata = (struct gids_private_data*) card->drv_data;
  391|    104|	int r;
  392|    104|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    104|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    104|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    104|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 104]
  |  |  ------------------
  ------------------
  393|    104|	if (privatedata->masterfilesize == sizeof(privatedata->masterfile)) {
  ------------------
  |  Branch (393:6): [True: 12, False: 92]
  ------------------
  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: 5, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|     12|	}
  397|     99|	r = gids_read_gidsfile_without_cache(card, privatedata->masterfile, privatedata->masterfilesize,
  398|     99|		directory, filename, response, responselen);
  399|     99|	LOG_TEST_RET(card->ctx, r, "unable to read the file");
  ------------------
  |  |  174|     99|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     99|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     99|	int _ret = (r); \
  |  |  |  |  168|     99|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 99, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     99|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     99|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     99|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     99|		return _ret; \
  |  |  |  |  172|     99|	} \
  |  |  |  |  173|     99|} 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|    143|static int gids_read_masterfile(sc_card_t* card) {
  345|    143|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  346|    143|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    143|#define SC_SUCCESS				0
  ------------------
  347|       |
  348|    143|	data->masterfilesize = sizeof(data->masterfile);
  349|    143|	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   66|    143|#define MF_FI UserCreateDeleteDirAc_FI
  |  |  ------------------
  |  |  |  |   63|    143|#define UserCreateDeleteDirAc_FI 0xA000
  |  |  ------------------
  ------------------
              	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   67|    143|#define MF_DO 0xDF1F
  ------------------
  350|    143|	if (r<0) {
  ------------------
  |  Branch (350:6): [True: 39, False: 104]
  ------------------
  351|     39|		data->masterfilesize = sizeof(data->masterfile);
  352|     39|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|     39|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     39|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     39|	int _ret = r; \
  |  |  |  |  155|     39|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     39|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     39|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     39|	return _ret; \
  |  |  |  |  163|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|     39|	}
  354|    104|	if (data->masterfilesize < 1 || data->masterfile[0] != 1) {
  ------------------
  |  Branch (354:6): [True: 1, False: 103]
  |  Branch (354:34): [True: 5, False: 98]
  ------------------
  355|      6|		data->masterfilesize = sizeof(data->masterfile);
  356|      6|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  357|      6|	}
  358|     98|	return r;
  359|    104|}
card-gids.c:gids_read_gidsfile_without_cache:
  312|     99|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|     99|	int r;
  314|     99|	int fileIdentifier;
  315|     99|	int dataObjectIdentifier;
  316|       |
  317|     99|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     99|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     99|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     99|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 99]
  |  |  ------------------
  ------------------
  318|     99|	r = gids_get_identifiers(card, masterfile, masterfilesize, directory, filename, &fileIdentifier, &dataObjectIdentifier);
  319|     99|	LOG_TEST_RET(card->ctx, r, "unable to get the identifier for the gids file");
  ------------------
  |  |  174|     99|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     99|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     99|	int _ret = (r); \
  |  |  |  |  168|     99|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 97, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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|     99|} 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|     99|static int gids_get_identifiers(sc_card_t* card, u8* masterfile, size_t masterfilesize, char *directory, char *filename, int *fileIdentifier, int *dataObjectIdentifier) {
  164|     99|	gids_mf_record_t *records = (gids_mf_record_t *) (masterfile+1);
  165|     99|	size_t recordcount = ((masterfilesize-1) / sizeof(gids_mf_record_t));
  166|     99|	size_t i;
  167|     99|	if (masterfilesize < 1)
  ------------------
  |  Branch (167:6): [True: 0, False: 99]
  ------------------
  168|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  169|       |
  170|    219|	for (i = 0; i < recordcount; i++) {
  ------------------
  |  Branch (170:14): [True: 122, False: 97]
  ------------------
  171|    122|		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: 69, False: 53]
  |  Branch (171:86): [True: 2, False: 67]
  ------------------
  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|    122|	}
  179|     97|	sc_log(card->ctx, "file %s %s not found\n", directory, filename);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  180|     97|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     97|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  181|     99|}
card-gids.c:gids_get_all_containers:
 1081|    131|gids_get_all_containers(sc_card_t* card, size_t *recordsnum) {
 1082|    131|	int r;
 1083|    131|	struct gids_private_data *privatedata = (struct gids_private_data *) card->drv_data;
 1084|    131|	r = gids_read_masterfile(card);
 1085|    131|	LOG_TEST_RET(card->ctx, r, "unable to read the masterfile");
  ------------------
  |  |  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: 40, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  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|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1086|     91|	r = gids_read_cmapfile(card);
 1087|     91|	LOG_TEST_RET(card->ctx, r, "unable to read the cmapfile");
  ------------------
  |  |  174|     91|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     91|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     91|	int _ret = (r); \
  |  |  |  |  168|     91|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 91, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     91|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     91|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     91|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     91|		return _ret; \
  |  |  |  |  172|     91|	} \
  |  |  |  |  173|     91|} 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|     91|}
card-gids.c:gids_read_cmapfile:
  431|     91|static int gids_read_cmapfile(sc_card_t* card) {
  432|     91|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  433|     91|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     91|#define SC_SUCCESS				0
  ------------------
  434|       |
  435|     91|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     91|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     91|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     91|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 91]
  |  |  ------------------
  ------------------
  436|     91|	data->cmapfilesize = sizeof(data->cmapfile);
  437|     91|	r = gids_read_gidsfile(card, "mscp", "cmapfile", data->cmapfile, &data->cmapfilesize);
  438|     91|	if (r<0) {
  ------------------
  |  Branch (438:6): [True: 91, False: 0]
  ------------------
  439|     91|		data->cmapfilesize = sizeof(data->cmapfile);
  440|     91|	}
  441|     91|	LOG_TEST_RET(card->ctx, r, "unable to get the cmapfile");
  ------------------
  |  |  174|     91|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     91|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     91|	int _ret = (r); \
  |  |  |  |  168|     91|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 91, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     91|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     91|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     91|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     91|		return _ret; \
  |  |  |  |  172|     91|	} \
  |  |  |  |  173|     91|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  442|      0|	return r;
  443|     91|}
card-gids.c:gids_pin_cmd:
 1029|     13|gids_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data) {
 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);
 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.68k|{
 2137|  3.68k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.68k|#define SC_SUCCESS				0
  ------------------
 2138|       |
 2139|  3.68k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.68k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.68k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.68k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.68k]
  |  |  ------------------
  ------------------
 2140|       |
 2141|  3.68k|	if (was_reset > 0) {
  ------------------
  |  Branch (2141:6): [True: 0, False: 3.68k]
  ------------------
 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.68k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.68k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.68k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.68k|	int _ret = r; \
  |  |  |  |  155|  3.68k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.68k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.68k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.68k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.68k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.68k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.68k|	return _ret; \
  |  |  |  |  163|  3.68k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2148|  3.68k|}

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

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

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

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

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

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

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

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

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

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

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

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

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

populate_blobs_to_mf:
  381|    784|{
  382|    784|	pgp_do_info_t	*info;
  383|  45.4k|	for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (383:33): [True: 45.4k, False: 0]
  |  Branch (383:51): [True: 44.6k, False: 784]
  ------------------
  384|  44.6k|		if (((info->access & READ_MASK) != READ_NEVER) && (info->get_fn != NULL)) {
  ------------------
  |  Branch (384:7): [True: 32.5k, False: 12.0k]
  |  Branch (384:53): [True: 14.7k, False: 17.8k]
  ------------------
  385|  14.7k|			pgp_blob_t *child = NULL;
  386|  14.7k|			sc_file_t *file = sc_file_new();
  387|       |
  388|  14.7k|			child = pgp_new_blob(card, priv->mf, info->id, file);
  389|       |
  390|       |			/* catch out of memory condition */
  391|  14.7k|			if (child == NULL) {
  ------------------
  |  Branch (391:8): [True: 0, False: 14.7k]
  ------------------
  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|  14.7k|		}
  396|  44.6k|	}
  397|    784|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 784]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|    784|}
_pgp_add_algo:
  736|  1.02k|{
  737|  1.02k|	unsigned long flags = 0, ext_flags = 0;
  738|       |
  739|  1.02k|	if (!card || !key_info)
  ------------------
  |  Branch (739:6): [True: 0, False: 1.02k]
  |  Branch (739:15): [True: 0, False: 1.02k]
  ------------------
  740|      0|		return 0;
  741|       |
  742|       |	/* [RFC 4880], [draft-ietf-openpgp-crypto-refresh] */
  743|  1.02k|	switch (key_info->algorithm) {
  744|  1.02k|	case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  869|  1.02k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (744:2): [True: 1.02k, 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.02k|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 |
  ------------------
  |  |  120|  1.02k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  1.02k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|  1.02k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  748|  1.02k|			SC_ALGORITHM_RSA_HASH_NONE |
  ------------------
  |  |  142|  1.02k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  749|  1.02k|			SC_ALGORITHM_ONBOARD_KEY_GEN;	/* key gen on card */
  ------------------
  |  |  102|  1.02k|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  750|       |
  751|  1.02k|		_sc_card_add_rsa_alg(card, key_info->u.rsa.modulus_len, flags, 0);
  752|  1.02k|		sc_log(card->ctx, "DO %uX: Added RSA algorithm, mod_len = %"
  ------------------
  |  |   71|  1.02k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  753|  1.02k|			SC_FORMAT_LEN_SIZE_T"u",
  754|  1.02k|			do_num, key_info->u.rsa.modulus_len);
  755|  1.02k|		break;
  756|      0|	case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  870|      0|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (756:2): [True: 0, False: 1.02k]
  ------------------
  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.02k]
  ------------------
  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.02k]
  ------------------
  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.02k]
  ------------------
  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.02k|	}
  795|       |	/* return true */
  796|  1.02k|	return 1;
  797|  1.02k|}
sc_get_openpgp_driver:
 4211|  16.4k|{
 4212|  16.4k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 4213|       |
 4214|  16.4k|	iso_ops = iso_drv->ops;
 4215|       |
 4216|  16.4k|	pgp_ops = *iso_ops;
 4217|  16.4k|	pgp_ops.match_card	= pgp_match_card;
 4218|  16.4k|	pgp_ops.init		= pgp_init;
 4219|  16.4k|	pgp_ops.finish		= pgp_finish;
 4220|  16.4k|	pgp_ops.select_file	= pgp_select_file;
 4221|  16.4k|	pgp_ops.list_files	= pgp_list_files;
 4222|  16.4k|	pgp_ops.get_challenge	= pgp_get_challenge;
 4223|  16.4k|	pgp_ops.read_binary	= pgp_read_binary;
 4224|  16.4k|	pgp_ops.write_binary	= NULL;
 4225|  16.4k|	pgp_ops.pin_cmd		= pgp_pin_cmd;
 4226|  16.4k|	pgp_ops.logout		= pgp_logout;
 4227|  16.4k|	pgp_ops.get_data	= pgp_get_data;
 4228|  16.4k|	pgp_ops.put_data	= pgp_put_data;
 4229|  16.4k|	pgp_ops.set_security_env= pgp_set_security_env;
 4230|  16.4k|	pgp_ops.compute_signature= pgp_compute_signature;
 4231|  16.4k|	pgp_ops.decipher	= pgp_decipher;
 4232|  16.4k|	pgp_ops.card_ctl	= pgp_card_ctl;
 4233|  16.4k|	pgp_ops.delete_file	= pgp_delete_file;
 4234|  16.4k|	pgp_ops.update_binary	= pgp_update_binary;
 4235|  16.4k|	pgp_ops.card_reader_lock_obtained = pgp_card_reader_lock_obtained;
 4236|       |
 4237|  16.4k|	return &pgp_drv;
 4238|  16.4k|}
card-openpgp.c:pgp_new_blob:
 1237|  40.9k|{
 1238|  40.9k|	pgp_blob_t *blob = NULL;
 1239|       |
 1240|  40.9k|	if (file == NULL)
  ------------------
  |  Branch (1240:6): [True: 0, False: 40.9k]
  ------------------
 1241|      0|		return NULL;
 1242|       |
 1243|  40.9k|	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  ------------------
  |  Branch (1243:6): [True: 40.9k, False: 0]
  ------------------
 1244|  40.9k|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  40.9k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1245|  40.9k|		pgp_do_info_t *info;
 1246|       |
 1247|  40.9k|		blob->file = file;
 1248|       |
 1249|  40.9k|		blob->file->type         = SC_FILE_TYPE_WORKING_EF; /* default */
  ------------------
  |  |  216|  40.9k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1250|  40.9k|		blob->file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|  40.9k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1251|  40.9k|		blob->file->id           = file_id;
 1252|       |
 1253|  40.9k|		blob->id     = file_id;
 1254|  40.9k|		blob->parent = parent;
 1255|       |
 1256|  40.9k|		if (parent != NULL) {
  ------------------
  |  Branch (1256:7): [True: 40.1k, False: 784]
  ------------------
 1257|  40.1k|			pgp_blob_t **p;
 1258|       |
 1259|       |			/* set file's path = parent's path + file's id */
 1260|  40.1k|			blob->file->path = parent->file->path;
 1261|  40.1k|			sc_append_file_id(&blob->file->path, file_id);
 1262|       |
 1263|       |			/* append blob to list of parent's children */
 1264|  3.11M|			for (p = &parent->files; *p != NULL; p = &(*p)->next)
  ------------------
  |  Branch (1264:29): [True: 3.07M, False: 40.1k]
  ------------------
 1265|  3.07M|				;
 1266|  40.1k|			*p = blob;
 1267|  40.1k|		}
 1268|    784|		else {
 1269|    784|			char path[10] = "0000";	/* long enough */
 1270|       |
 1271|       |			/* no parent: set file's path = file's id */
 1272|    784|			if (4 != snprintf(path, sizeof(path), "%04X", file_id & 0xFFFF)) {
  ------------------
  |  Branch (1272:8): [True: 0, False: 784]
  ------------------
 1273|      0|				free(blob);
 1274|      0|				return NULL;
 1275|      0|			}
 1276|       |
 1277|    784|			sc_format_path(path, &blob->file->path);
 1278|    784|		}
 1279|       |
 1280|       |		/* find matching DO info: set file type depending on it */
 1281|  1.57M|		for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (1281:34): [True: 1.57M, False: 0]
  |  Branch (1281:52): [True: 1.56M, False: 10.7k]
  ------------------
 1282|  1.56M|			if (info->id == file_id) {
  ------------------
  |  Branch (1282:8): [True: 30.1k, False: 1.53M]
  ------------------
 1283|  30.1k|				blob->info = info;
 1284|  30.1k|				blob->file->type = blob->info->type;
 1285|  30.1k|				pgp_attach_acl(card, blob->file, info);
 1286|  30.1k|				break;
 1287|  30.1k|			}
 1288|  1.56M|		}
 1289|  40.9k|	}
 1290|       |
 1291|  40.9k|	return blob;
 1292|  40.9k|}
card-openpgp.c:pgp_attach_acl:
 1169|  30.1k|{
 1170|  30.1k|	unsigned int method = SC_AC_NONE;
  ------------------
  |  |  150|  30.1k|#define SC_AC_NONE			0x00000000
  ------------------
 1171|  30.1k|	unsigned long key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  30.1k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1172|       |
 1173|       |	/* Write access */
 1174|  30.1k|	switch (info->access & WRITE_MASK) {
  ------------------
  |  Branch (1174:10): [True: 30.1k, False: 0]
  ------------------
 1175|  10.3k|	case WRITE_NEVER:
  ------------------
  |  Branch (1175:2): [True: 10.3k, False: 19.8k]
  ------------------
 1176|  10.3k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  10.3k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1177|  10.3k|		break;
 1178|      0|	case WRITE_PIN1:
  ------------------
  |  Branch (1178:2): [True: 0, False: 30.1k]
  ------------------
 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.56k|	case WRITE_PIN2:
  ------------------
  |  Branch (1182:2): [True: 1.56k, False: 28.6k]
  ------------------
 1183|  1.56k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  1.56k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1184|  1.56k|		key_ref = 0x02;
 1185|  1.56k|		break;
 1186|  18.2k|	case WRITE_PIN3:
  ------------------
  |  Branch (1186:2): [True: 18.2k, False: 11.9k]
  ------------------
 1187|  18.2k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  18.2k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1188|  18.2k|		key_ref = 0x03;
 1189|  18.2k|		break;
 1190|  30.1k|	}
 1191|       |
 1192|  30.1k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  60.3k|#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: 30.1k, False: 0]
  |  Branch (1192:30): [True: 0, False: 0]
  ------------------
 1193|  30.1k|		sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|  30.1k|#define SC_AC_OP_WRITE			24
  ------------------
 1194|  30.1k|		sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|  30.1k|#define SC_AC_OP_UPDATE			23
  ------------------
 1195|  30.1k|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|  30.1k|#define SC_AC_OP_DELETE			2
  ------------------
 1196|  30.1k|		sc_file_add_acl_entry(file, SC_AC_OP_CREATE, method, key_ref);
  ------------------
  |  |  169|  30.1k|#define SC_AC_OP_CREATE			3
  ------------------
 1197|  30.1k|	}
 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|  30.1k|	method = SC_AC_NONE;
  ------------------
  |  |  150|  30.1k|#define SC_AC_NONE			0x00000000
  ------------------
 1205|  30.1k|	key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  30.1k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1206|       |	/* Read access */
 1207|  30.1k|	switch (info->access & READ_MASK) {
  ------------------
  |  Branch (1207:10): [True: 2.92k, False: 27.2k]
  ------------------
 1208|  1.35k|	case READ_NEVER:
  ------------------
  |  Branch (1208:2): [True: 1.35k, False: 28.8k]
  ------------------
 1209|  1.35k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.35k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1210|  1.35k|		break;
 1211|      0|	case READ_PIN1:
  ------------------
  |  Branch (1211:2): [True: 0, False: 30.1k]
  ------------------
 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|    784|	case READ_PIN2:
  ------------------
  |  Branch (1215:2): [True: 784, False: 29.4k]
  ------------------
 1216|    784|		method = SC_AC_CHV;
  ------------------
  |  |  151|    784|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1217|    784|		key_ref = 0x02;
 1218|    784|		break;
 1219|    784|	case READ_PIN3:
  ------------------
  |  Branch (1219:2): [True: 784, False: 29.4k]
  ------------------
 1220|    784|		method = SC_AC_CHV;
  ------------------
  |  |  151|    784|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1221|    784|		key_ref = 0x03;
 1222|    784|		break;
 1223|  30.1k|	}
 1224|       |
 1225|  30.1k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  60.3k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|  27.2k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1225:6): [True: 2.92k, False: 27.2k]
  |  Branch (1225:30): [True: 0, False: 27.2k]
  ------------------
 1226|  2.92k|		sc_file_add_acl_entry(file, SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|  2.92k|#define SC_AC_OP_READ			22
  ------------------
 1227|  2.92k|	}
 1228|  30.1k|}
card-openpgp.c:pgp_match_card:
  326|  3.42k|{
  327|  3.42k|	int i;
  328|       |
  329|  3.42k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.42k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.42k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.42k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.42k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.42k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|       |
  331|  3.42k|	i = _sc_match_atr(card, pgp_atrs, &card->type);
  332|  3.42k|	if (i >= 0) {
  ------------------
  |  Branch (332:6): [True: 194, False: 3.22k]
  ------------------
  333|    194|		card->name = pgp_atrs[i].name;
  334|    194|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    194|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    194|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    194|	int _ret = r; \
  |  |  |  |  155|    194|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 194]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    194|	} else { \
  |  |  |  |  159|    194|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    194|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    194|	} \
  |  |  |  |  162|    194|	return _ret; \
  |  |  |  |  163|    194|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|    194|	}
  336|  3.22k|	else {
  337|  3.22k|		sc_path_t	partial_aid;
  338|  3.22k|		sc_file_t *file = NULL;
  339|       |
  340|       |		/* select application "OpenPGP" */
  341|  3.22k|		sc_format_path("D276:0001:2401", &partial_aid);
  342|  3.22k|		partial_aid.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  3.22k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  343|       |		/* OpenPGP card only supports selection *with* requested FCI */
  344|  3.22k|		i = iso_ops->select_file(card, &partial_aid, &file);
  345|  3.22k|		if (SC_SUCCESS == i) {
  ------------------
  |  |   28|  3.22k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:7): [True: 615, False: 2.61k]
  ------------------
  346|    615|			card->type = SC_CARD_TYPE_OPENPGP_BASE;
  347|    615|			card->name = default_cardname;
  348|       |
  349|    615|			if (file->namelen != 16)
  ------------------
  |  Branch (349:8): [True: 614, False: 1]
  ------------------
  350|    614|				(void) get_full_pgp_aid(card, file);
  351|    615|			if (file->namelen == 16) {
  ------------------
  |  Branch (351:8): [True: 24, False: 591]
  ------------------
  352|     24|				unsigned char major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|     24|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  353|       |
  354|     24|				switch (major) {
  355|      4|					case 1:
  ------------------
  |  Branch (355:6): [True: 4, False: 20]
  ------------------
  356|      4|						card->type = SC_CARD_TYPE_OPENPGP_V1;
  357|      4|						card->name = default_cardname_v1;
  358|      4|						break;
  359|     13|					case 2:
  ------------------
  |  Branch (359:6): [True: 13, False: 11]
  ------------------
  360|     13|						card->type = SC_CARD_TYPE_OPENPGP_V2;
  361|     13|						card->name = default_cardname_v2;
  362|     13|						break;
  363|      4|					case 3:
  ------------------
  |  Branch (363:6): [True: 4, False: 20]
  ------------------
  364|      4|						card->type = SC_CARD_TYPE_OPENPGP_V3;
  365|      4|						card->name = default_cardname_v3;
  366|      4|						break;
  367|      3|					default:
  ------------------
  |  Branch (367:6): [True: 3, False: 21]
  ------------------
  368|      3|						break;
  369|     24|				}
  370|     24|			}
  371|    615|			sc_file_free(file);
  372|    615|			LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    615|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    615|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    615|	int _ret = r; \
  |  |  |  |  155|    615|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 615]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    615|	} else { \
  |  |  |  |  159|    615|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    615|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    615|	} \
  |  |  |  |  162|    615|	return _ret; \
  |  |  |  |  163|    615|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    615|		}
  374|  3.22k|	}
  375|  2.61k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  2.61k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.61k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.61k|	int _ret = r; \
  |  |  |  |  155|  2.61k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.61k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.61k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.61k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.61k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.61k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.61k|	return _ret; \
  |  |  |  |  163|  2.61k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|  2.61k|}
card-openpgp.c:get_full_pgp_aid:
  307|  1.40k|{
  308|  1.40k|	int r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.40k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  309|       |
  310|  1.40k|	if (file != NULL) {
  ------------------
  |  Branch (310:6): [True: 1.40k, False: 0]
  ------------------
  311|       |		/* explicitly get the full aid */
  312|  1.40k|		r = sc_get_data(card, 0x004F, file->name, sizeof file->name);
  313|  1.40k|		file->namelen = MAX(r, 0);
  ------------------
  |  |   67|  1.40k|#define MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (67:20): [True: 661, False: 743]
  |  |  ------------------
  ------------------
  314|  1.40k|	}
  315|       |
  316|  1.40k|	return r;
  317|  1.40k|}
card-openpgp.c:pgp_init:
  405|    809|{
  406|    809|	struct pgp_priv_data *priv;
  407|    809|	sc_path_t	path;
  408|    809|	sc_file_t	*file = NULL;
  409|    809|	int		r, i;
  410|       |
  411|    809|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    809|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    809|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    809|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    809|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 809]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|       |
  413|    809|	priv = calloc (1, sizeof *priv);
  414|    809|	if (!priv)
  ------------------
  |  Branch (414:6): [True: 0, False: 809]
  ------------------
  415|    809|		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|    809|	card->drv_data = priv;
  417|       |
  418|    809|	card->cla = 0x00;
  419|       |
  420|       |	/* select application "OpenPGP" */
  421|    809|	sc_format_path("D276:0001:2401", &path);
  422|    809|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    809|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  423|    809|	if ((r = iso_ops->select_file(card, &path, &file)) < 0) {
  ------------------
  |  Branch (423:6): [True: 18, False: 791]
  ------------------
  424|     18|		sc_file_free(file);
  425|     18|		pgp_finish(card);
  426|     18|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  427|     18|	}
  428|       |
  429|       |	/* defensive programming check */
  430|    791|	if (!file)   {
  ------------------
  |  Branch (430:6): [True: 0, False: 791]
  ------------------
  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|    791|	if (file->namelen != 16) {
  ------------------
  |  Branch (435:6): [True: 790, False: 1]
  ------------------
  436|       |		/* explicitly get the full aid */
  437|    790|		r = get_full_pgp_aid(card, file);
  438|    790|		if (r < 0) {
  ------------------
  |  Branch (438:7): [True: 7, False: 783]
  ------------------
  439|      7|			sc_file_free(file);
  440|      7|			pgp_finish(card);
  441|      7|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  442|      7|		}
  443|    790|	}
  444|       |
  445|       |	/* read information from AID */
  446|    784|	if (file->namelen == 16) {
  ------------------
  |  Branch (446:6): [True: 432, False: 352]
  ------------------
  447|    432|		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|    432|		priv->bcd_version = bebytes2ushort(file->name + 6);
  451|    432|		card->version.fw_major = card->version.hw_major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|    432|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  452|    432|		card->version.fw_minor = card->version.hw_minor = BCD2UCHAR(file->name[7]);
  ------------------
  |  |  216|    432|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  453|       |
  454|       |		/* for "standard" cards, include detailed card version & serial no. in card name */
  455|    432|		if (card->name == default_cardname_v1 ||
  ------------------
  |  Branch (455:7): [True: 1, False: 431]
  ------------------
  456|    431|		    card->name == default_cardname_v2 ||
  ------------------
  |  Branch (456:7): [True: 2, False: 429]
  ------------------
  457|    429|		    card->name == default_cardname_v3) {
  ------------------
  |  Branch (457:7): [True: 2, False: 427]
  ------------------
  458|      5|			snprintf(card_name, sizeof(card_name),
  459|      5|				 "OpenPGP card v%u.%u (%04X %08lX)",
  460|      5|				 card->version.hw_major, card->version.hw_minor,
  461|      5|				 bebytes2ushort(file->name + 8),
  462|      5|				 bebytes2ulong(file->name + 10));
  463|      5|		}
  464|    427|		else if (card->name != NULL) {
  ------------------
  |  Branch (464:12): [True: 427, False: 0]
  ------------------
  465|       |			/* for other cards, append serial number to the card name */
  466|    427|			snprintf(card_name, sizeof(card_name),
  467|    427|				 "%s (%04X %08lX)",
  468|    427|				 card->name,
  469|    427|				 bebytes2ushort(file->name + 8),
  470|    427|				 bebytes2ulong(file->name + 10));
  471|    427|		}
  472|    432|		card->name = card_name;
  473|       |
  474|       |		/* GPG compatibility: set card's serial number to manufacturer ID + serial number */
  475|    432|		memcpy(card->serialnr.value, file->name + 8, 6);
  476|    432|		card->serialnr.len = 6;
  477|    432|	} else {
  478|       |		/* set detailed card version */
  479|    352|		switch (card->type) {
  480|      1|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (480:4): [True: 1, False: 351]
  ------------------
  481|      1|				priv->bcd_version = OPENPGP_CARD_3_0;
  482|      1|				break;
  483|    172|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (483:4): [True: 172, False: 180]
  ------------------
  484|    182|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (484:4): [True: 10, False: 342]
  ------------------
  485|    182|				priv->bcd_version = OPENPGP_CARD_2_0;
  486|    182|				break;
  487|    169|			default:
  ------------------
  |  Branch (487:4): [True: 169, False: 183]
  ------------------
  488|    169|				priv->bcd_version = OPENPGP_CARD_1_1;
  489|    169|				break;
  490|    352|		}
  491|    352|	}
  492|       |
  493|       |	/* set pointer to correct list of card objects */
  494|    784|	priv->pgp_objects = (priv->bcd_version < OPENPGP_CARD_2_0) ? pgp1x_objects
  ------------------
  |  Branch (494:22): [True: 212, False: 572]
  ------------------
  495|    784|			  : (priv->bcd_version < OPENPGP_CARD_2_1) ? pgp20_objects
  ------------------
  |  Branch (495:8): [True: 182, False: 390]
  ------------------
  496|    572|			  : (priv->bcd_version < OPENPGP_CARD_3_0) ? pgp21_objects
  ------------------
  |  Branch (496:8): [True: 14, False: 376]
  ------------------
  497|    390|			  : (priv->bcd_version < OPENPGP_CARD_3_3) ? pgp30_objects
  ------------------
  |  Branch (497:8): [True: 5, False: 371]
  ------------------
  498|    376|			  : (priv->bcd_version < OPENPGP_CARD_3_4) ? pgp33_objects
  ------------------
  |  Branch (498:8): [True: 1, False: 370]
  ------------------
  499|    371|			  :					     pgp34_objects;
  500|       |
  501|       |	/* With gnuk, we use different curves */
  502|    784|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (502:6): [True: 190, False: 594]
  ------------------
  503|    190|		priv->ec_curves = ec_curves_gnuk;
  504|    594|	} else if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (504:13): [True: 363, False: 231]
  ------------------
  505|    363|		priv->ec_curves = ec_curves_openpgp34;
  506|    363|	} else {
  507|    231|		priv->ec_curves = ec_curves_openpgp;
  508|    231|	}
  509|       |
  510|       |	/* change file path to MF for reuse in MF */
  511|    784|	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|    784|	priv->mf = pgp_new_blob(card, NULL, 0x3f00, file);
  516|    784|	if (!priv->mf) {
  ------------------
  |  Branch (516:6): [True: 0, False: 784]
  ------------------
  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|    784|	priv->current = priv->mf;
  524|       |
  525|    784|	r = populate_blobs_to_mf(card, priv);
  526|    784|	if (r < 0) {
  ------------------
  |  Branch (526:6): [True: 0, False: 784]
  ------------------
  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|    784|	if (pgp_get_card_features(card)) {
  ------------------
  |  Branch (532:6): [True: 30, False: 754]
  ------------------
  533|     30|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     30|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     30|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     30|	int _ret = r; \
  |  |  |  |  155|     30|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     30|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  157|     30|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     30|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     30|	return _ret; \
  |  |  |  |  163|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|     30|	}
  535|       |
  536|       |	/* if algorithm attributes can be changed,
  537|       |	 * add supported algorithms based on specification for pkcs15-init */
  538|    754|	if (priv->ext_caps & EXT_CAP_ALG_ATTR_CHANGEABLE) {
  ------------------
  |  Branch (538:6): [True: 70, False: 684]
  ------------------
  539|     70|		unsigned long flags_rsa, flags_ecc, ext_flags;
  540|     70|		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|     70|		flags_rsa = SC_ALGORITHM_RSA_PAD_PKCS1|
  ------------------
  |  |  120|     70|#define SC_ALGORITHM_RSA_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|     70|#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|     70|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  544|     70|			    SC_ALGORITHM_RSA_HASH_NONE|
  ------------------
  |  |  142|     70|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  545|     70|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     70|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  546|     70|		flags_ecc = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  183|     70|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  547|     70|			    SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  182|     70|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  548|     70|			    SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  184|     70|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|     70|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  549|     70|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     70|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  550|     70|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  210|     70|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  551|       |
  552|     70|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW |
  ------------------
  |  |  197|     70|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  553|     70|			      SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     70|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  554|       |		/* xeddsa may allow signing at some time */
  555|     70|		flags_xeddsa = SC_ALGORITHM_ECDH_CDH_RAW |
  ------------------
  |  |  182|     70|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  556|     70|			       SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     70|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  557|       |
  558|     70|		switch (card->type) {
  559|      1|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (559:4): [True: 1, False: 69]
  ------------------
  560|       |				/* RSA 1024 was removed for v3+ */
  561|      1|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  562|      1|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  563|       |				/* fallthrough */
  564|     39|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (564:4): [True: 38, False: 32]
  ------------------
  565|     39|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  566|    280|				for (i=0; priv->ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (566:15): [True: 241, False: 39]
  ------------------
  567|    241|				{
  568|    241|					if (priv->ec_curves[i].key_type == SC_ALGORITHM_EC)
  ------------------
  |  |   79|    241|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (568:10): [True: 85, False: 156]
  ------------------
  569|     85|						_sc_card_add_ec_alg(card, priv->ec_curves[i].size,
  570|     85|								flags_ecc, ext_flags, &priv->ec_curves[i].oid);
  571|    156|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   81|    156|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (571:15): [True: 78, False: 78]
  ------------------
  572|     78|						_sc_card_add_eddsa_alg(card, priv->ec_curves[i].size,
  573|     78|								flags_eddsa, ext_flags, &priv->ec_curves[i].oid);
  574|     78|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|     78|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (574:15): [True: 78, False: 0]
  ------------------
  575|     78|						_sc_card_add_xeddsa_alg(card, priv->ec_curves[i].size,
  576|     78|								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|    241|				}
  580|     39|				break;
  581|     39|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (581:4): [True: 1, False: 69]
  ------------------
  582|     31|			default:
  ------------------
  |  Branch (582:4): [True: 30, False: 40]
  ------------------
  583|     31|				_sc_card_add_rsa_alg(card, 1024, flags_rsa, 0);
  584|     31|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  585|     31|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  586|     31|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  587|     31|				break;
  588|     70|		}
  589|     70|	}
  590|       |
  591|    754|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    754|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 754]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  592|    754|}
card-openpgp.c:pgp_get_blob:
 1477|  12.7k|{
 1478|  12.7k|	pgp_blob_t		*child;
 1479|  12.7k|	int			r;
 1480|       |
 1481|  12.7k|	if ((r = pgp_enumerate_blob(card, blob)) < 0)
  ------------------
  |  Branch (1481:6): [True: 1.10k, False: 11.6k]
  ------------------
 1482|  1.10k|		return r;
 1483|       |
 1484|  83.7k|	for (child = blob->files; child; child = child->next) {
  ------------------
  |  Branch (1484:28): [True: 81.6k, False: 2.11k]
  ------------------
 1485|  81.6k|		if (child->id == id) {
  ------------------
  |  Branch (1485:7): [True: 9.48k, False: 72.1k]
  ------------------
 1486|  9.48k|			(void) pgp_read_blob(card, child);
 1487|  9.48k|			*ret = child;
 1488|  9.48k|			return SC_SUCCESS;
  ------------------
  |  |   28|  9.48k|#define SC_SUCCESS				0
  ------------------
 1489|  9.48k|		}
 1490|  81.6k|	}
 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|  2.11k|	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  154|  4.23k|#define DO_CARDHOLDER            0x65
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  155|    574|#define DO_NAME                  0x5b
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  156|    574|#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: 287, False: 1.83k]
  |  Branch (1497:36): [True: 0, False: 287]
  |  Branch (1497:53): [True: 287, False: 0]
  |  Branch (1497:75): [True: 0, False: 0]
  ------------------
 1498|    287|		sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
  ------------------
  |  |   71|    287|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1499|    287|		child = pgp_new_blob(card, blob, id, sc_file_new());
 1500|    287|		if (child) {
  ------------------
  |  Branch (1500:7): [True: 287, False: 0]
  ------------------
 1501|    287|			pgp_set_blob(child, NULL, 0);
 1502|    287|			*ret = child;
 1503|    287|			return SC_SUCCESS;
  ------------------
  |  |   28|    287|#define SC_SUCCESS				0
  ------------------
 1504|    287|		}
 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|    287|			       "Not enough memory to create blob for DO %X",
 1508|    287|			       id);
 1509|    287|	}
 1510|       |
 1511|  1.83k|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.83k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 1512|  2.11k|}
card-openpgp.c:pgp_enumerate_blob:
 1395|  13.0k|{
 1396|  13.0k|	const u8	*in;
 1397|  13.0k|	int		r;
 1398|  13.0k|	sc_file_t	*file = NULL;
 1399|       |
 1400|  13.0k|	if (blob->files != NULL)
  ------------------
  |  Branch (1400:6): [True: 10.7k, False: 2.34k]
  ------------------
 1401|  10.7k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.7k|#define SC_SUCCESS				0
  ------------------
 1402|       |
 1403|  2.34k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1403:6): [True: 982, False: 1.36k]
  ------------------
 1404|    982|		return r;
 1405|       |
 1406|  1.36k|	in = blob->data;
 1407|       |
 1408|  26.6k|	while ((int) blob->len > (in - blob->data)) {
  ------------------
  |  Branch (1408:9): [True: 25.6k, False: 942]
  ------------------
 1409|  25.6k|		unsigned int	cla, tag, tmptag;
 1410|  25.6k|		size_t		len;
 1411|  25.6k|		const u8	*data = in;
 1412|  25.6k|		pgp_blob_t	*new;
 1413|       |
 1414|  25.6k|		if (!in)
  ------------------
  |  Branch (1414:7): [True: 0, False: 25.6k]
  ------------------
 1415|      0|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      0|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1416|       |
 1417|  25.6k|		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
 1418|  25.6k|					&cla, &tag, &len);
 1419|  25.6k|		if (r == SC_ERROR_INVALID_ASN1_OBJECT) {
  ------------------
  |  |   82|  25.6k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (1419:7): [True: 121, False: 25.5k]
  ------------------
 1420|    121|			sc_log(card->ctx, "Invalid ASN.1 object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1421|    121|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    121|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1422|    121|		}
 1423|       |		/* Check for unknown error, or empty data */
 1424|  25.5k|		if (((r < 0) && (r != SC_ERROR_ASN1_END_OF_CONTENTS)) ||
  ------------------
  |  |   84|    255|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1424:8): [True: 255, False: 25.3k]
  |  Branch (1424:19): [True: 0, False: 255]
  ------------------
 1425|  25.5k|		    (data == NULL)) {
  ------------------
  |  Branch (1425:7): [True: 85, False: 25.4k]
  ------------------
 1426|     85|			sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1427|     85|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|     85|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1428|     85|		}
 1429|       |
 1430|       |		/* undo ASN1's split of tag & class */
 1431|  26.0k|		for (tmptag = tag; tmptag > 0x0FF; tmptag >>= 8) {
  ------------------
  |  Branch (1431:22): [True: 565, False: 25.4k]
  ------------------
 1432|    565|			cla <<= 8;
 1433|    565|		}
 1434|  25.4k|		tag |= cla;
 1435|       |		/* Check for length mismatch */
 1436|  25.4k|		if ((r == SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|  25.4k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1436:7): [True: 255, False: 25.2k]
  ------------------
 1437|  25.2k|		    (data + len > blob->data + blob->len)) {
  ------------------
  |  Branch (1437:7): [True: 0, False: 25.2k]
  ------------------
 1438|       |			// Check if it is not known Yubikey 5 issue
 1439|    255|			if ((tag != blob->id) || (tag != 0xfa)) {
  ------------------
  |  Branch (1439:8): [True: 209, False: 46]
  |  Branch (1439:29): [True: 10, False: 36]
  ------------------
 1440|    219|				sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    219|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1441|    219|				return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    219|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1442|    219|			}
 1443|    255|		}
 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|  25.2k|		if (tag == blob->id) {
  ------------------
  |  Branch (1448:7): [True: 214, False: 25.0k]
  ------------------
 1449|    214|			in = data;
 1450|    214|			continue;
 1451|    214|		}
 1452|       |
 1453|       |		/* create fake file system hierarchy by
 1454|       |		 * using constructed DOs as DF */
 1455|  25.0k|		file = sc_file_new();
 1456|  25.0k|		if ((new = pgp_new_blob(card, blob, tag, file)) == NULL) {
  ------------------
  |  Branch (1456:7): [True: 0, False: 25.0k]
  ------------------
 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|  25.0k|		if (pgp_set_blob(new, data, len) != SC_SUCCESS) {
  ------------------
  |  |   28|  25.0k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1460:7): [True: 0, False: 25.0k]
  ------------------
 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|  25.0k|		in = data + len;
 1465|  25.0k|	}
 1466|       |
 1467|    942|	return SC_SUCCESS;
  ------------------
  |  |   28|    942|#define SC_SUCCESS				0
  ------------------
 1468|  1.36k|}
card-openpgp.c:pgp_set_blob:
 1137|  26.7k|{
 1138|  26.7k|	if (blob->data)
  ------------------
  |  Branch (1138:6): [True: 0, False: 26.7k]
  ------------------
 1139|      0|		free(blob->data);
 1140|  26.7k|	blob->data = NULL;
 1141|  26.7k|	blob->len    = 0;
 1142|  26.7k|	blob->status = 0;
 1143|       |
 1144|  26.7k|	if (len > 0) {
  ------------------
  |  Branch (1144:6): [True: 12.4k, False: 14.2k]
  ------------------
 1145|  12.4k|		void *tmp = calloc(1, len);
 1146|       |
 1147|  12.4k|		if (tmp == NULL)
  ------------------
  |  Branch (1147:7): [True: 0, False: 12.4k]
  ------------------
 1148|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1149|       |
 1150|  12.4k|		blob->data = tmp;
 1151|  12.4k|		blob->len  = (unsigned int)len;
 1152|  12.4k|		if (data != NULL)
  ------------------
  |  Branch (1152:7): [True: 12.4k, False: 0]
  ------------------
 1153|  12.4k|			memcpy(blob->data, data, len);
 1154|  12.4k|	}
 1155|       |
 1156|  26.7k|	if (blob->file)
  ------------------
  |  Branch (1156:6): [True: 26.7k, False: 0]
  ------------------
 1157|  26.7k|		blob->file->size = len;
 1158|       |
 1159|  26.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  26.7k|#define SC_SUCCESS				0
  ------------------
 1160|  26.7k|}
card-openpgp.c:pgp_read_blob:
 1345|  14.9k|{
 1346|  14.9k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  14.9k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1347|       |
 1348|  14.9k|	if (blob->data != NULL)
  ------------------
  |  Branch (1348:6): [True: 10.5k, False: 4.35k]
  ------------------
 1349|  10.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.5k|#define SC_SUCCESS				0
  ------------------
 1350|  4.35k|	if (blob->info == NULL)
  ------------------
  |  Branch (1350:6): [True: 0, False: 4.35k]
  ------------------
 1351|      0|		return blob->status;
 1352|       |
 1353|  4.35k|	if (blob->info->get_fn) {	/* readable, top-level DO */
  ------------------
  |  Branch (1353:6): [True: 4.29k, False: 64]
  ------------------
 1354|  4.29k|		u8 	buffer[MAX_OPENPGP_DO_SIZE];
 1355|  4.29k|		size_t	buf_len = sizeof(buffer);
 1356|  4.29k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  4.29k|#define SC_SUCCESS				0
  ------------------
 1357|       |
 1358|       |		/* buffer length for certificate */
 1359|  4.29k|		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
  ------------------
  |  |  138|  8.58k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (1359:7): [True: 195, False: 4.09k]
  |  Branch (1359:30): [True: 42, False: 153]
  ------------------
 1360|     42|			buf_len = MIN(priv->max_cert_size, sizeof(buffer));
  ------------------
  |  |   70|     42|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 17, False: 25]
  |  |  ------------------
  ------------------
 1361|     42|		}
 1362|       |
 1363|       |		/* buffer length for Gnuk pubkey */
 1364|  4.29k|		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (1364:7): [True: 983, False: 3.30k]
  ------------------
 1365|    983|		    (blob->id == DO_AUTH ||
  ------------------
  |  |  143|  1.96k|#define DO_AUTH                  0xa400
  ------------------
  |  Branch (1365:8): [True: 0, False: 983]
  ------------------
 1366|    983|		     blob->id == DO_SIGN ||
  ------------------
  |  |  141|  1.96k|#define DO_SIGN                  0xb600
  ------------------
  |  Branch (1366:8): [True: 0, False: 983]
  ------------------
 1367|    983|		     blob->id == DO_ENCR ||
  ------------------
  |  |  142|  1.96k|#define DO_ENCR                  0xb800
  ------------------
  |  Branch (1367:8): [True: 0, False: 983]
  ------------------
 1368|    983|		     blob->id == DO_AUTH_SYM ||
  ------------------
  |  |  147|  1.96k|#define DO_AUTH_SYM              0xa401
  ------------------
  |  Branch (1368:8): [True: 0, False: 983]
  ------------------
 1369|    983|		     blob->id == DO_SIGN_SYM ||
  ------------------
  |  |  145|  1.96k|#define DO_SIGN_SYM              0xb601
  ------------------
  |  Branch (1369:8): [True: 0, False: 983]
  ------------------
 1370|    983|		     blob->id == DO_ENCR_SYM)) {
  ------------------
  |  |  146|    983|#define DO_ENCR_SYM              0xb801
  ------------------
  |  Branch (1370:8): [True: 0, False: 983]
  ------------------
 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|  4.29k|		r = blob->info->get_fn(card, blob->id, buffer, buf_len);
 1375|       |
 1376|  4.29k|		if (r < 0) {	/* an error occurred */
  ------------------
  |  Branch (1376:7): [True: 2.84k, False: 1.44k]
  ------------------
 1377|  2.84k|			blob->status = r;
 1378|  2.84k|			return r;
 1379|  2.84k|		}
 1380|       |
 1381|  1.44k|		return pgp_set_blob(blob, buffer, r);
 1382|  4.29k|	}
 1383|     64|	else {		/* un-readable DO or part of a constructed DO */
 1384|     64|		return SC_SUCCESS;
  ------------------
  |  |   28|     64|#define SC_SUCCESS				0
  ------------------
 1385|     64|	}
 1386|  4.35k|}
card-openpgp.c:pgp_parse_algo_attr_blob:
  630|  8.47k|{
  631|  8.47k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  8.47k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  632|  8.47k|	struct sc_object_id oid;
  633|  8.47k|	unsigned int j, r;
  634|       |
  635|  8.47k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  8.47k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  8.47k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  8.47k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  8.47k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8.47k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|  8.47k|	if (blob == NULL || blob->data == NULL || blob->len == 0 ||
  ------------------
  |  Branch (637:6): [True: 0, False: 8.47k]
  |  Branch (637:22): [True: 1.50k, False: 6.97k]
  |  Branch (637:44): [True: 0, False: 6.97k]
  ------------------
  638|  6.97k|	    blob->id < 0x00c1 || blob->id > 0x00c3 || key_info == NULL) {
  ------------------
  |  Branch (638:6): [True: 0, False: 6.97k]
  |  Branch (638:27): [True: 0, False: 6.97k]
  |  Branch (638:48): [True: 0, False: 6.97k]
  ------------------
  639|  1.50k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|  1.50k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.50k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.50k|	int _ret = r; \
  |  |  |  |  155|  1.50k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.50k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.50k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.50k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.50k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.50k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.50k|	return _ret; \
  |  |  |  |  163|  1.50k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|  1.50k|	}
  641|       |
  642|  6.97k|	key_info->key_id = blob->id - 0x00c0;	/* attribute algorithm blobs are C1 - C3 */
  643|       |
  644|  6.97k|	switch (blob->data[0]) {
  645|  1.73k|		case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  869|  1.73k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (645:3): [True: 1.73k, False: 5.24k]
  ------------------
  646|  1.73k|			if (blob->len < 5) {
  ------------------
  |  Branch (646:8): [True: 702, False: 1.02k]
  ------------------
  647|    702|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|    702|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    702|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    702|	int _ret = r; \
  |  |  |  |  155|    702|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 702, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    702|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    702|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 702, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    702|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    702|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    702|	return _ret; \
  |  |  |  |  163|    702|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  648|    702|			}
  649|       |
  650|  1.02k|			key_info->algorithm = SC_OPENPGP_KEYALGO_RSA;
  ------------------
  |  |  869|  1.02k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  651|  1.02k|			key_info->u.rsa.modulus_len = bebytes2ushort(blob->data + 1);
  652|  1.02k|			key_info->u.rsa.exponent_len = bebytes2ushort(blob->data + 3);
  653|       |
  654|  1.02k|			key_info->u.rsa.keyformat = (blob->len > 5)
  ------------------
  |  Branch (654:32): [True: 373, False: 655]
  ------------------
  655|  1.02k|						  ? blob->data[5]
  656|  1.02k|						  : SC_OPENPGP_KEYFORMAT_RSA_STD;
  ------------------
  |  |  874|  1.68k|#define SC_OPENPGP_KEYFORMAT_RSA_STD	0    /* See 4.3.3.6 Algorithm Attributes */
  ------------------
  657|  1.02k|			break;
  658|  2.01k|		case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  870|  2.01k|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (658:3): [True: 2.01k, False: 4.95k]
  ------------------
  659|  3.44k|		case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  871|  3.44k|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (659:3): [True: 1.42k, False: 5.54k]
  ------------------
  660|  4.03k|		case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  872|  4.03k|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (660:3): [True: 597, False: 6.37k]
  ------------------
  661|       |
  662|       |			/* SC_OPENPGP_KEYALGO_ECDH || SC_OPENPGP_KEYALGO_ECDSA || SC_OPENPGP_KEYALGO_EDDSA */
  663|  4.03k|			key_info->algorithm = blob->data[0];
  664|       |
  665|       |			/* last byte is set to 0xFF if pubkey import is supported */
  666|  4.03k|			if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB){
  ------------------
  |  |  880|  4.03k|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (666:8): [True: 1.21k, False: 2.81k]
  ------------------
  667|  1.21k|				if (blob->len < 3)
  ------------------
  |  Branch (667:9): [True: 487, False: 732]
  ------------------
  668|    487|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    487|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  669|    732|				key_info->u.ec.oidv_len = blob->len - 2;
  670|    732|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STDPUB;
  ------------------
  |  |  880|    732|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  671|    732|			}
  672|  2.81k|			else {
  673|       |				/* otherwise, last byte could be 00, so let's ignore it, as
  674|       |				 * it is not part of OID */
  675|  2.81k|				if (blob->len < 2)
  ------------------
  |  Branch (675:9): [True: 408, False: 2.41k]
  ------------------
  676|    408|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    408|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  677|  2.41k|				if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STD)
  ------------------
  |  |  879|  2.41k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (677:9): [True: 552, False: 1.85k]
  ------------------
  678|    552|					key_info->u.ec.oidv_len = blob->len - 2;
  679|  1.85k|				else
  680|  1.85k|					key_info->u.ec.oidv_len = blob->len - 1;
  681|  2.41k|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STD;
  ------------------
  |  |  879|  2.41k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  682|  2.41k|			}
  683|       |
  684|       |			/* Create copy of oid from blob */
  685|  3.14k|			sc_init_oid(&oid);
  686|  3.14k|			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.14k|			if (r > 0){
  ------------------
  |  Branch (689:8): [True: 2.01k, False: 1.13k]
  ------------------
  690|  2.01k|				return r;
  691|  2.01k|			}
  692|       |			/* compare with list of supported ec_curves */
  693|  15.6k|			for (j = 0; priv->ec_curves[j].oid.value[0] >= 0; j++) {
  ------------------
  |  Branch (693:16): [True: 14.5k, False: 1.13k]
  ------------------
  694|  14.5k|				if (sc_compare_oid(&priv->ec_curves[j].oid, &oid)) {
  ------------------
  |  Branch (694:9): [True: 0, False: 14.5k]
  ------------------
  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|  14.5k|			}
  702|       |			/* We did not match the OID */
  703|  1.13k|			if (priv->ec_curves[j].oid.value[0] < 0) {
  ------------------
  |  Branch (703:8): [True: 1.13k, False: 0]
  ------------------
  704|  1.13k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  705|  1.13k|			}
  706|      0|			break;
  707|  1.20k|		default:
  ------------------
  |  Branch (707:3): [True: 1.20k, False: 5.76k]
  ------------------
  708|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  6.97k|	}
  710|       |
  711|  1.02k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.02k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.02k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.02k|	int _ret = r; \
  |  |  |  |  155|  1.02k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.02k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.02k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.02k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.02k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.02k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.02k|	return _ret; \
  |  |  |  |  163|  1.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  712|  1.02k|}
card-openpgp.c:pgp_get_card_features:
  906|    784|{
  907|    784|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    784|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  908|    784|	u8 *hist_bytes = card->reader->atr_info.hist_bytes;
  909|    784|	size_t hist_bytes_len = card->reader->atr_info.hist_bytes_len;
  910|    784|	unsigned int i;
  911|    784|	pgp_blob_t *blob, *blob6e, *blob73, *blobfa;
  912|    784|	int handled_algos = 0;
  913|       |
  914|    784|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  915|       |
  916|       |	/* parse card capabilities from historical bytes in ATR */
  917|    784|	if (hist_bytes_len > 0) {
  ------------------
  |  Branch (917:6): [True: 315, False: 469]
  ------------------
  918|       |		/* category indicator 0x00, 0x10 or 0x80 => compact TLV (ISO) */
  919|    315|		switch (hist_bytes[0]) {
  ------------------
  |  Branch (919:11): [True: 225, False: 90]
  ------------------
  920|    212|			case 0x00:
  ------------------
  |  Branch (920:4): [True: 212, False: 103]
  ------------------
  921|    212|				if (hist_bytes_len > 4) {
  ------------------
  |  Branch (921:9): [True: 209, False: 3]
  ------------------
  922|    209|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-4);
  923|    209|				}
  924|    212|				break;
  925|     11|			case 0x80:
  ------------------
  |  Branch (925:4): [True: 11, False: 304]
  ------------------
  926|     11|				if (hist_bytes_len > 1) {
  ------------------
  |  Branch (926:9): [True: 10, False: 1]
  ------------------
  927|     10|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-1);
  928|     10|				}
  929|     11|				break;
  930|      2|			case 0x10:
  ------------------
  |  Branch (930:4): [True: 2, False: 313]
  ------------------
  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|    315|		}
  936|    315|	}
  937|       |
  938|       |	/* v1.1 does not support lifecycle via ACTIVATE & TERMINATE: set default */
  939|    784|	priv->ext_caps &= ~EXT_CAP_LCS;
  940|       |
  941|    784|	if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (941:6): [True: 572, False: 212]
  ------------------
  942|       |		/* get card capabilities from "historical bytes" DO */
  943|    572|		if ((pgp_get_blob(card, priv->mf, 0x5f52, &blob) >= 0) &&
  ------------------
  |  Branch (943:7): [True: 572, False: 0]
  ------------------
  944|    572|		    (blob->data != NULL) && (blob->data[0] == 0x00)) {
  ------------------
  |  Branch (944:7): [True: 45, False: 527]
  |  Branch (944:31): [True: 34, False: 11]
  ------------------
  945|       |
  946|     34|			if (blob->len > 4) {
  ------------------
  |  Branch (946:8): [True: 33, False: 1]
  ------------------
  947|     33|				pgp_parse_hist_bytes(card, blob->data+1, blob->len-4);
  948|     33|			}
  949|       |
  950|       |			/* get card status from historical bytes status indicator */
  951|     34|			if ((blob->data[0] == 0x00) && (blob->len >= 4)) {
  ------------------
  |  Branch (951:8): [True: 34, False: 0]
  |  Branch (951:35): [True: 33, False: 1]
  ------------------
  952|     33|				priv->state = blob->data[blob->len-3];
  953|       |				/* state not CARD_STATE_UNKNOWN => LCS supported */
  954|     33|				if (priv->state != CARD_STATE_UNKNOWN)
  ------------------
  |  Branch (954:9): [True: 25, False: 8]
  ------------------
  955|     25|					priv->ext_caps |= EXT_CAP_LCS;
  956|     33|			}
  957|     34|		}
  958|    572|	}
  959|       |
  960|    784|	if (priv->bcd_version >= OPENPGP_CARD_3_1) {
  ------------------
  |  Branch (960:6): [True: 372, False: 412]
  ------------------
  961|    372|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    372|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  962|    372|	}
  963|       |
  964|    784|	if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (964:6): [True: 370, False: 414]
  ------------------
  965|       |		/* Parse supported algorithms from Algorithm Information DO
  966|       |		 * see OpenPGP card spec 3.4 section 4.4.3.11 */
  967|    370|		if (pgp_get_blob(card, priv->mf, 0x00fa, &blobfa) >= 0) {
  ------------------
  |  Branch (967:7): [True: 370, False: 0]
  ------------------
  968|    370|			pgp_blob_t *child;
  969|    370|			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|  12.7k|			for (child = blobfa->files; child; child = child->next) {
  ------------------
  |  Branch (972:32): [True: 12.3k, False: 370]
  ------------------
  973|  12.3k|				if ((child->id < 0x00c1) || (child->id > 0x00c3))
  ------------------
  |  Branch (973:9): [True: 2.91k, False: 9.45k]
  |  Branch (973:33): [True: 1.52k, False: 7.92k]
  ------------------
  974|  4.43k|					continue;
  975|  7.92k|				sc_cardctl_openpgp_key_gen_store_info_t key_info;
  976|  7.92k|				if (pgp_parse_algo_attr_blob(card, child, &key_info) >= 0)
  ------------------
  |  Branch (976:9): [True: 761, False: 7.16k]
  ------------------
  977|    761|					handled_algos += _pgp_add_algo(card, &key_info, 0x00fa);
  978|  7.92k|			}
  979|    370|		}
  980|    370|	}
  981|       |
  982|       |	/* v1.1 & v2.x: special DOs are limited to 254 bytes */
  983|    784|	priv->max_specialDO_size = 254;
  984|       |
  985|    784|	if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
  ------------------
  |  Branch (985:6): [True: 784, False: 0]
  ------------------
  986|    784|	    (pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {
  ------------------
  |  Branch (986:6): [True: 239, False: 545]
  ------------------
  987|       |
  988|       |		/* get "extended capabilities" DO */
  989|    239|		if ((pgp_get_blob(card, blob73, 0x00c0, &blob) >= 0) &&
  ------------------
  |  Branch (989:7): [True: 85, False: 154]
  ------------------
  990|     85|		    (blob->data != NULL) && (blob->len > 0)) {
  ------------------
  |  Branch (990:7): [True: 84, False: 1]
  |  Branch (990:31): [True: 84, False: 0]
  ------------------
  991|     84|			if ((blob->data[0] & 0x01) && (priv->bcd_version >= OPENPGP_CARD_3_3)) {
  ------------------
  |  Branch (991:8): [True: 31, False: 53]
  |  Branch (991:34): [True: 17, False: 14]
  ------------------
  992|     17|				priv->ext_caps |= EXT_CAP_KDF_DO;
  993|     17|			}
  994|       |			/* v2.0+: bit 0x04 in first byte means "algorithm attributes changeable" */
  995|     84|			if ((blob->data[0] & 0x04) &&
  ------------------
  |  Branch (995:8): [True: 72, False: 12]
  ------------------
  996|     72|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (996:6): [True: 70, False: 2]
  ------------------
  997|     70|				priv->ext_caps |= EXT_CAP_ALG_ATTR_CHANGEABLE;
  998|       |			/* bit 0x08 in first byte means "support for private use DOs" */
  999|     84|			if (blob->data[0] & 0x08)
  ------------------
  |  Branch (999:8): [True: 40, False: 44]
  ------------------
 1000|     40|				priv->ext_caps |= EXT_CAP_PRIVATE_DO;
 1001|       |			/* bit 0x10 in first byte means "support for CHV status byte changeable" */
 1002|     84|			if (blob->data[0] & 0x10)
  ------------------
  |  Branch (1002:8): [True: 23, False: 61]
  ------------------
 1003|     23|				priv->ext_caps |= EXT_CAP_C4_CHANGEABLE;
 1004|       |			/* bit 0x20 in first byte means "support for Key Import" */
 1005|     84|			if (blob->data[0] & 0x20)
  ------------------
  |  Branch (1005:8): [True: 44, False: 40]
  ------------------
 1006|     44|				priv->ext_caps |= EXT_CAP_KEY_IMPORT;
 1007|       |			/* bit 0x40 in first byte means "support for Get Challenge" */
 1008|     84|			if (blob->data[0] & 0x40) {
  ------------------
  |  Branch (1008:8): [True: 45, False: 39]
  ------------------
 1009|     45|				card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|     45|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 1010|     45|				priv->ext_caps |= EXT_CAP_GET_CHALLENGE;
 1011|     45|			}
 1012|       |			/* v2.0+: bit 0x80 in first byte means "support Secure Messaging" */
 1013|     84|			if ((blob->data[0] & 0x80) &&
  ------------------
  |  Branch (1013:8): [True: 45, False: 39]
  ------------------
 1014|     45|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (1014:6): [True: 43, False: 2]
  ------------------
 1015|     43|				priv->ext_caps |= EXT_CAP_SM;
 1016|       |
 1017|     84|			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
  ------------------
  |  Branch (1017:8): [True: 82, False: 2]
  |  Branch (1017:51): [True: 66, False: 16]
  ------------------
 1018|       |				/* v2.0+: max. challenge size is at bytes 3-4 */
 1019|     66|				priv->max_challenge_size = bebytes2ushort(blob->data + 2);
 1020|       |				/* v2.0+: max. cert size it at bytes 5-6 */
 1021|     66|				priv->max_cert_size = bebytes2ushort(blob->data + 4);
 1022|       |
 1023|     66|				if (priv->bcd_version < OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1023:9): [True: 44, False: 22]
  ------------------
 1024|       |					/* v2.x: SM algorithm is at byte 2: 0 == 3DES */
 1025|     44|					priv->sm_algo = blob->data[1];
 1026|     44|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1026:10): [True: 27, False: 17]
  |  Branch (1026:45): [True: 24, False: 3]
  ------------------
 1027|     24|						priv->sm_algo = SM_ALGO_3DES;
 1028|       |
 1029|       |					/* v2.x: max. send/receive sizes are at bytes 7-8 resp. 9-10 */
 1030|     44|					card->max_send_size = bebytes2ushort(blob->data + 6);
 1031|     44|					card->max_recv_size = bebytes2ushort(blob->data + 8);
 1032|     44|				}
 1033|     22|				else {
 1034|       |					/* v3.0+: SM algorithm is at byte 2: 0 == UNKNOWN */
 1035|     22|					priv->sm_algo = blob->data[1];
 1036|     22|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1036:10): [True: 10, False: 12]
  |  Branch (1036:45): [True: 3, False: 7]
  ------------------
 1037|      3|						priv->sm_algo = SM_ALGO_UNKNOWN;
 1038|       |
 1039|       |					/* v3.0+: max. size of special DOs is at bytes 7-8 */
 1040|     22|					priv->max_specialDO_size = bebytes2ushort(blob->data + 6);
 1041|     22|				}
 1042|     66|				if (priv->bcd_version >= OPENPGP_CARD_3_3 && (blob->len >= 10)) {
  ------------------
  |  Branch (1042:9): [True: 22, False: 44]
  |  Branch (1042:50): [True: 22, False: 0]
  ------------------
 1043|       |					/* v3.3+: MSE for key numbers 2(DEC) and 3(AUT) supported */
 1044|     22|					if (blob->data[9])
  ------------------
  |  Branch (1044:10): [True: 16, False: 6]
  ------------------
 1045|     16|						priv->ext_caps |= EXT_CAP_MSE;
 1046|     22|				}
 1047|     66|			}
 1048|     84|		}
 1049|       |
 1050|       |		/* get max. PIN length from "CHV status bytes" DO */
 1051|    239|		if ((pgp_get_blob(card, blob73, 0x00c4, &blob) >= 0) &&
  ------------------
  |  Branch (1051:7): [True: 199, False: 40]
  ------------------
 1052|    199|			(blob->data != NULL) && (blob->len > 1)) {
  ------------------
  |  Branch (1052:4): [True: 197, False: 2]
  |  Branch (1052:28): [True: 196, False: 1]
  ------------------
 1053|       |			/* 2nd byte in "CHV status bytes" DO means "max. PIN length" */
 1054|    196|			card->max_pin_len = blob->data[1];
 1055|    196|		}
 1056|       |
 1057|    239|		if (priv->bcd_version >= OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1057:7): [True: 121, False: 118]
  ------------------
 1058|       |			/* v3.0+: get length info from "extended length information" DO */
 1059|    121|			if ((pgp_get_blob(card, blob6e, 0x7f66, &blob) >= 0) &&
  ------------------
  |  Branch (1059:8): [True: 2, False: 119]
  ------------------
 1060|      2|				(blob->data != NULL) && (blob->len >= 8)) {
  ------------------
  |  Branch (1060:5): [True: 1, False: 1]
  |  Branch (1060:29): [True: 0, False: 1]
  ------------------
 1061|       |				/* kludge: treat as SIMPLE DO and use appropriate offsets */
 1062|      0|				card->max_send_size = bebytes2ushort(blob->data + 2);
 1063|      0|				card->max_recv_size = bebytes2ushort(blob->data + 6);
 1064|      0|			}
 1065|    121|		}
 1066|       |
 1067|    239|#ifdef ENABLE_OPENSSL
 1068|    239|		if (priv->ext_caps & EXT_CAP_KDF_DO) {
  ------------------
  |  Branch (1068:7): [True: 17, False: 222]
  ------------------
 1069|     17|			int r = pgp_decode_kdf_do(card, priv);
 1070|     17|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  |  Branch (1070:8): [True: 16, False: 1]
  ------------------
 1071|     16|				sc_log(card->ctx, "Failed to decode KDF DO: %s", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1072|     16|			}
 1073|     17|		}
 1074|    239|#endif /* ENABLE_OPENSSL */
 1075|       |
 1076|       |		/* if we found at least one usable algo, let's skip other ways to find them */
 1077|    239|		if (handled_algos) {
  ------------------
  |  Branch (1077:7): [True: 0, False: 239]
  ------------------
 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|    956|		for (i = 0x00c1; i <= 0x00c3; i++) {
  ------------------
  |  Branch (1088:20): [True: 717, False: 239]
  ------------------
 1089|    717|			sc_cardctl_openpgp_key_gen_store_info_t key_info;
 1090|       |
 1091|    717|			sc_log(card->ctx, "Parsing algorithm attributes DO %uX" , i);
  ------------------
  |  |   71|    717|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1092|       |
 1093|       |			/* OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1094|    717|			if ((pgp_get_blob(card, blob73, i, &blob) >= 0) &&
  ------------------
  |  Branch (1094:8): [True: 549, False: 168]
  ------------------
 1095|    549|			    (pgp_parse_algo_attr_blob(card, blob, &key_info) >= 0)) {
  ------------------
  |  Branch (1095:8): [True: 267, False: 282]
  ------------------
 1096|    267|				if (!_pgp_add_algo(card, &key_info, i))
  ------------------
  |  Branch (1096:9): [True: 0, False: 267]
  ------------------
 1097|    267|					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|    267|			}
 1099|    717|		}
 1100|       |
 1101|    239|	}
 1102|       |
 1103|    784|	LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  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: 754, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 754]
  |  |  |  |  ------------------
  |  |  |  |  157|    754|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    754|	} else { \
  |  |  |  |  159|     30|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     30|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     30|	} \
  |  |  |  |  162|    784|	return _ret; \
  |  |  |  |  163|    784|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1104|    784|}
card-openpgp.c:pgp_parse_hist_bytes:
  600|    253|{
  601|    253|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    253|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  602|    253|	const u8 *ptr;
  603|       |
  604|       |	/* IS07816-4 hist bytes: 3rd function table */
  605|    253|	if ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x73, NULL)) != NULL) {
  ------------------
  |  Branch (605:6): [True: 207, False: 46]
  ------------------
  606|       |		/* bit 0x40 in byte 3 of TL 0x73 means "extended Le/Lc" */
  607|    207|		if (ptr[2] & 0x40) {
  ------------------
  |  Branch (607:7): [True: 12, False: 195]
  ------------------
  608|     12|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|     12|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  609|     12|			priv->ext_caps |= EXT_CAP_APDU_EXT;
  610|     12|		}
  611|       |		/* bit 0x80 in byte 3 of TL 0x73 means "Command chaining" */
  612|    207|		if (ptr[2] & 0x80) {
  ------------------
  |  Branch (612:7): [True: 198, False: 9]
  ------------------
  613|    198|			priv->ext_caps |= EXT_CAP_CHAINING;
  614|    198|		}
  615|    207|	}
  616|       |
  617|    253|	if ((priv->bcd_version >= OPENPGP_CARD_3_0) &&
  ------------------
  |  Branch (617:6): [True: 45, False: 208]
  ------------------
  618|     45|	    ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x31, NULL)) != NULL)) {
  ------------------
  |  Branch (618:6): [True: 18, False: 27]
  ------------------
  619|       |		// ToDo ...
  620|     18|	}
  621|    253|}
card-openpgp.c:pgp_decode_kdf_do:
  802|     17|{
  803|     17|	pgp_pin_kdf_info_t *pin_kdf_info = (pgp_pin_kdf_info_t *)calloc(1, sizeof(pgp_pin_kdf_info_t));
  804|     17|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|     17|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  805|     17|	pgp_blob_t *kdf_blob;
  806|     17|	const uint8_t *data;
  807|     17|	size_t data_len;
  808|     17|	size_t tag_len;
  809|     17|	const uint8_t *p;
  810|     17|	pgp_blob_t *blob;
  811|       |
  812|     17|	if (!pin_kdf_info) {
  ------------------
  |  Branch (812:6): [True: 0, False: 17]
  ------------------
  813|      0|		return r;
  814|      0|	}
  815|       |
  816|     17|	r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     17|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  817|     17|	priv->pin_kdf_info = NULL;
  818|     17|	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |  159|     17|#define DO_KDF                   0xf9
  ------------------
              	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  |  Branch (818:6): [True: 0, False: 17]
  |  Branch (818:73): [True: 4, False: 13]
  ------------------
  819|      4|		sc_log(card->ctx, "KDF DO does not exists or contains invalid data but card claims to support it");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  820|      4|		goto out;
  821|      4|	}
  822|       |
  823|     13|	data = kdf_blob->data;
  824|     13|	data_len = kdf_blob->len;
  825|     13|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x81, &tag_len);
  826|     13|	if (!p) {
  ------------------
  |  Branch (826:6): [True: 1, False: 12]
  ------------------
  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|     12|	if (tag_len != 1) {
  ------------------
  |  Branch (830:6): [True: 3, False: 9]
  ------------------
  831|      3|		sc_log(card->ctx, "Unexpected KDF algorithm byte length, expects 1, got %" SC_FORMAT_LEN_SIZE_T "u", tag_len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  832|      3|		goto out;
  833|      3|	}
  834|       |
  835|      9|	if (*p != 0x3) {
  ------------------
  |  Branch (835:6): [True: 2, False: 7]
  ------------------
  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|      7|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x82, &tag_len);
  846|      7|	if (!p) {
  ------------------
  |  Branch (846:6): [True: 1, False: 6]
  ------------------
  847|      1|		sc_log(card->ctx, "KDF hash algorithm byte not found");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  848|      1|		goto out;
  849|      1|	}
  850|      6|	if (tag_len != 1) {
  ------------------
  |  Branch (850:6): [True: 1, False: 5]
  ------------------
  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|      5|	switch (*p) {
  856|      1|	case 0x08:
  ------------------
  |  Branch (856:2): [True: 1, False: 4]
  ------------------
  857|      1|		pin_kdf_info->hash_algo = "SHA256";
  858|      1|		break;
  859|      3|	case 0x0A:
  ------------------
  |  Branch (859:2): [True: 3, False: 2]
  ------------------
  860|      3|		pin_kdf_info->hash_algo = "SHA512";
  861|      3|		break;
  862|      1|	default:
  ------------------
  |  Branch (862:2): [True: 1, False: 4]
  ------------------
  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|      5|	}
  866|       |
  867|      4|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x83, &tag_len);
  868|      4|	if (!p) {
  ------------------
  |  Branch (868:6): [True: 2, False: 2]
  ------------------
  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|      2|	if (tag_len != 4) {
  ------------------
  |  Branch (872:6): [True: 1, False: 1]
  ------------------
  873|      1|		sc_log(card->ctx, "Unexpected KDF iteration count length, expects 4, 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__
  |  |  ------------------
  ------------------
  874|      1|		goto out;
  875|      1|	}
  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|     17|out:
  896|     17|	free(pin_kdf_info);
  897|     17|	return r;
  898|      0|}
card-openpgp.c:pgp_finish:
 1112|    809|{
 1113|    809|	if (card != NULL) {
  ------------------
  |  Branch (1113:6): [True: 809, False: 0]
  ------------------
 1114|    809|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    809|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1115|       |
 1116|    809|		if (priv != NULL) {
  ------------------
  |  Branch (1116:7): [True: 809, False: 0]
  ------------------
 1117|       |			/* delete fake file hierarchy */
 1118|    809|			pgp_free_blobs(priv->mf);
 1119|       |
 1120|       |			/* delete kdf do related data if exists */
 1121|    809|			free(priv->pin_kdf_info);
 1122|       |
 1123|       |			/* delete private data */
 1124|    809|			free(priv);
 1125|    809|		}
 1126|    809|		card->drv_data = NULL;
 1127|    809|	}
 1128|    809|	return SC_SUCCESS;
  ------------------
  |  |   28|    809|#define SC_SUCCESS				0
  ------------------
 1129|    809|}
card-openpgp.c:pgp_free_blobs:
 1325|  40.9k|{
 1326|  40.9k|	if (blob) {
  ------------------
  |  Branch (1326:6): [True: 40.9k, False: 25]
  ------------------
 1327|  40.9k|		pgp_blob_t *child = blob->files;
 1328|       |
 1329|  81.0k|		while (child != NULL) {
  ------------------
  |  Branch (1329:10): [True: 40.1k, False: 40.9k]
  ------------------
 1330|  40.1k|			pgp_blob_t *next = child->next;
 1331|       |
 1332|  40.1k|			pgp_free_blobs(child);
 1333|  40.1k|			child = next;
 1334|  40.1k|		}
 1335|  40.9k|		pgp_free_blob(blob);
 1336|  40.9k|	}
 1337|  40.9k|}
card-openpgp.c:pgp_free_blob:
 1300|  40.9k|{
 1301|  40.9k|	if (blob) {
  ------------------
  |  Branch (1301:6): [True: 40.9k, False: 0]
  ------------------
 1302|  40.9k|		if (blob->parent) {
  ------------------
  |  Branch (1302:7): [True: 40.1k, False: 784]
  ------------------
 1303|  40.1k|			pgp_blob_t **p;
 1304|       |
 1305|       |			/* remove blob from list of parent's children */
 1306|  40.1k|			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  ------------------
  |  Branch (1306:35): [True: 40.1k, False: 0]
  |  Branch (1306:49): [True: 0, False: 40.1k]
  ------------------
 1307|      0|				;
 1308|  40.1k|			if (*p == blob)
  ------------------
  |  Branch (1308:8): [True: 40.1k, False: 0]
  ------------------
 1309|  40.1k|				*p = blob->next;
 1310|  40.1k|		}
 1311|       |
 1312|  40.9k|		sc_file_free(blob->file);
 1313|  40.9k|		if (blob->data)
  ------------------
  |  Branch (1313:7): [True: 12.4k, False: 28.4k]
  ------------------
 1314|  12.4k|			free(blob->data);
 1315|  40.9k|		free(blob);
 1316|  40.9k|	}
 1317|  40.9k|}
card-openpgp.c:pgp_select_file:
 1611|  7.32k|{
 1612|  7.32k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  7.32k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1613|  7.32k|	pgp_blob_t	*blob;
 1614|  7.32k|	unsigned int	path_start = 0;
 1615|  7.32k|	unsigned int	n;
 1616|  7.32k|	sc_path_t dummy_path;
 1617|       |
 1618|  7.32k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  7.32k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.32k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.32k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.32k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.32k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|       |
 1620|  7.32k|	if (path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  7.32k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1620:6): [True: 1.13k, False: 6.18k]
  ------------------
 1621|  7.32k|		LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
  ------------------
  |  |  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.07k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.07k, False: 60]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|  6.18k|	if (path->len < 2 || (path->len & 1))
  ------------------
  |  Branch (1623:6): [True: 0, False: 6.18k]
  |  Branch (1623:23): [True: 0, False: 6.18k]
  ------------------
 1624|  6.18k|		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|  6.18k|				"invalid path length");
 1626|       |
 1627|  6.18k|	if (path->type == SC_PATH_TYPE_FILE_ID && path->len != 2)
  ------------------
  |  |  117|  12.3k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1627:6): [True: 0, False: 6.18k]
  |  Branch (1627:44): [True: 0, False: 0]
  ------------------
 1628|  6.18k|		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|  6.18k|				"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|  6.18k|	sc_format_path("11001101", &dummy_path);
 1638|  6.18k|	if (sc_compare_path(path, &dummy_path)) {
  ------------------
  |  Branch (1638:6): [True: 0, False: 6.18k]
  ------------------
 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|  6.18k|	path_start = pgp_strip_path(card, path);
 1650|       |
 1651|       |	/* starting with the MF ... */
 1652|  6.18k|	blob = priv->mf;
 1653|       |	/* ... recurse through the tree following the path */
 1654|  13.1k|	for (n = path_start; n < path->len; n += 2) {
  ------------------
  |  Branch (1654:23): [True: 8.86k, False: 4.27k]
  ------------------
 1655|  8.86k|		unsigned int	id = bebytes2ushort(path->value + n);
 1656|  8.86k|		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|  8.86k|		if (id == 0x4402 || id == 0x5f48) {
  ------------------
  |  Branch (1660:7): [True: 0, False: 8.86k]
  |  Branch (1660:23): [True: 0, False: 8.86k]
  ------------------
 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|  8.86k|		if (r < 0) {	/* failure */
  ------------------
  |  Branch (1671:7): [True: 1.90k, False: 6.95k]
  ------------------
 1672|  1.90k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.90k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.90k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.90k|	int _ret = r; \
  |  |  |  |  155|  1.90k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.90k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.90k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.90k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.90k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.90k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.90k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.90k|	return _ret; \
  |  |  |  |  163|  1.90k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1673|  1.90k|		}
 1674|  8.86k|	}
 1675|       |
 1676|       |	/* success: select file = set "current" pointer to blob found */
 1677|  4.27k|	priv->current = blob;
 1678|       |
 1679|  4.27k|	if (ret)
  ------------------
  |  Branch (1679:6): [True: 2.43k, False: 1.84k]
  ------------------
 1680|  2.43k|		sc_file_dup(ret, blob->file);
 1681|       |
 1682|  4.27k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  4.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.27k|	int _ret = r; \
  |  |  |  |  155|  4.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.27k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4.27k]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.27k|	return _ret; \
  |  |  |  |  163|  4.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1683|  4.27k|}
card-openpgp.c:pgp_strip_path:
 1592|  6.18k|{
 1593|  6.18k|	unsigned int start_point = 0;
 1594|       |	/* start_point will move through the path string */
 1595|  6.18k|	if (path->len == 0)
  ------------------
  |  Branch (1595:6): [True: 0, False: 6.18k]
  ------------------
 1596|      0|		return 0;
 1597|       |
 1598|       |	/* ignore 3F00 (MF) at the beginning */
 1599|  6.18k|	start_point = (memcmp(path->value, "\x3f\x00", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1599:16): [True: 3.28k, False: 2.89k]
  ------------------
 1600|       |	/* strip path of PKCS15-App DF (5015) */
 1601|  6.18k|	start_point += (memcmp(path->value + start_point, "\x50\x15", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1601:17): [True: 1.29k, False: 4.89k]
  ------------------
 1602|  6.18k|	return start_point;
 1603|  6.18k|}
card-openpgp.c:pgp_read_binary:
 1752|  3.07k|{
 1753|  3.07k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  3.07k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1754|  3.07k|	pgp_blob_t	*blob;
 1755|  3.07k|	int		r;
 1756|       |
 1757|  3.07k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.07k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.07k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.07k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.07k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1758|       |
 1759|       |	/* jump to selected file */
 1760|  3.07k|	blob = priv->current;
 1761|       |
 1762|  3.07k|	if (blob == NULL)
  ------------------
  |  Branch (1762:6): [True: 0, False: 3.07k]
  ------------------
 1763|  3.07k|		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|  3.07k|	if (blob->file->type != SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|  3.07k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (1765:6): [True: 0, False: 3.07k]
  ------------------
 1766|  3.07k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1767|       |
 1768|  3.07k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1768:6): [True: 0, False: 3.07k]
  ------------------
 1769|  3.07k|		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|  3.07k|	if (idx > blob->len)
  ------------------
  |  Branch (1771:6): [True: 0, False: 3.07k]
  ------------------
 1772|  3.07k|		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|  3.07k|	if (idx + count > blob->len)
  ------------------
  |  Branch (1774:6): [True: 0, False: 3.07k]
  ------------------
 1775|      0|		count = blob->len - idx;
 1776|  3.07k|	memcpy(buf, blob->data + idx, count);
 1777|       |
 1778|  3.07k|	LOG_FUNC_RETURN(card->ctx, (int)count);
  ------------------
  |  |  164|  3.07k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.07k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.07k|	int _ret = r; \
  |  |  |  |  155|  3.07k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 3.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|  3.07k|	} else { \
  |  |  |  |  159|  3.07k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.07k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.07k|	} \
  |  |  |  |  162|  3.07k|	return _ret; \
  |  |  |  |  163|  3.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|  3.07k|}
card-openpgp.c:pgp_pin_cmd:
 2389|  1.26k|{
 2390|  1.26k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  1.26k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2391|  1.26k|	struct sc_card_operations ops = {.pin_cmd = iso_ops->pin_cmd};
 2392|       |
 2393|  1.26k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.26k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.26k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.26k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.26k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.26k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2394|       |
 2395|  1.26k|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|  1.26k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2395:6): [True: 0, False: 1.26k]
  ------------------
 2396|  1.26k|		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.26k|				"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.26k|	data->pin_reference |= 0x80;
 2424|       |
 2425|       |	/* check version-dependent constraints */
 2426|  1.26k|	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  423|  2.53k|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  424|  1.15k|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2426:6): [True: 115, False: 1.15k]
  |  Branch (2426:40): [True: 107, False: 1.04k]
  ------------------
 2427|    222|		if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (2427:7): [True: 208, False: 14]
  ------------------
 2428|    208|			if (data->pin_reference == 0x82)
  ------------------
  |  Branch (2428:8): [True: 81, False: 127]
  ------------------
 2429|     81|				data->pin_reference = 0x81;
 2430|       |
 2431|    208|			if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  423|    208|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2431:8): [True: 107, False: 101]
  ------------------
 2432|    107|				if (data->pin1.len == 0 &&
  ------------------
  |  Branch (2432:9): [True: 0, False: 107]
  ------------------
 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|    107|					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|    107|							"v2 cards don't support implicit old PIN for PIN change");
 2436|       |
 2437|    107|				data->flags &= ~SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|    107|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2438|    107|			}
 2439|    208|		} else {
 2440|     14|			if (data->pin1.len != 0) {
  ------------------
  |  Branch (2440:8): [True: 14, False: 0]
  ------------------
 2441|     14|				sc_log(card->ctx,
  ------------------
  |  |   71|     14|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2442|     14|				       "v1 cards don't support explicit old or CHV3 PIN, PIN ignored.");
 2443|     14|				sc_log(card->ctx,
  ------------------
  |  |   71|     14|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2444|     14|				       "please make sure that you have verified the relevant PIN first.");
 2445|     14|				data->pin1.len = 0;
 2446|     14|			}
 2447|       |
 2448|     14|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|     14|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2449|     14|		}
 2450|    222|	}
 2451|       |
 2452|  1.26k|	if (data->cmd == SC_PIN_CMD_UNBLOCK && data->pin2.len == 0 &&
  ------------------
  |  |  424|  2.53k|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2452:6): [True: 107, False: 1.16k]
  |  Branch (2452:41): [True: 0, False: 107]
  ------------------
 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.26k|		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.26k|				"new PIN must be provided for unblock operation");
 2456|       |
 2457|       |	/* ensure pin_reference is 81, 82, 83 */
 2458|  1.26k|	if (data->pin_reference < 0x81 || data->pin_reference > 0x83)
  ------------------
  |  Branch (2458:6): [True: 15, False: 1.25k]
  |  Branch (2458:36): [True: 0, False: 1.25k]
  ------------------
 2459|  1.26k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2460|  1.25k|				"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.25k|	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  425|  2.50k|#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|    759|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (2463:6): [True: 759, False: 495]
  |  Branch (2463:42): [True: 416, False: 343]
  ------------------
 2464|    416|		u8 c4data[10];
 2465|    416|		int r;
 2466|       |
 2467|    416|		r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
 2468|    416|		LOG_TEST_RET(card->ctx, r, "reading CHV status bytes failed");
  ------------------
  |  |  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: 376, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  169|    376|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    376|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    376|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    376|		return _ret; \
  |  |  |  |  172|    376|	} \
  |  |  |  |  173|    416|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 40]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2469|       |
 2470|     40|		if (r != 7)
  ------------------
  |  Branch (2470:7): [True: 34, False: 6]
  ------------------
 2471|     40|			LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
  ------------------
  |  |  174|     34|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     34|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     34|	int _ret = (r); \
  |  |  |  |  168|     34|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     34|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     34|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     34|		return _ret; \
  |  |  |  |  172|     34|	} \
  |  |  |  |  173|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2472|      6|				"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|      6|		if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
  ------------------
  |  Branch (2479:7): [True: 5, False: 1]
  |  Branch (2479:48): [True: 2, False: 3]
  ------------------
 2480|      2|			data->pin_reference = 0x81;
 2481|       |
 2482|      6|		data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
 2483|      6|		data->pin1.max_tries = 3;
 2484|      6|		data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|      6|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 2485|       |
 2486|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2487|      6|	}
 2488|       |
 2489|    838|#ifdef ENABLE_OPENSSL
 2490|    838|	if (priv->pin_kdf_info) {
  ------------------
  |  Branch (2490:6): [True: 0, False: 838]
  ------------------
 2491|      0|		ops.pin_cmd = &pgp_kdf_do_pin_cmd;
 2492|      0|	}
 2493|    838|#endif /* ENABLE_OPENSSL */
 2494|       |
 2495|    838|	LOG_FUNC_RETURN(card->ctx, ops.pin_cmd(card, data));
  ------------------
  |  |  164|    838|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    838|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    838|	int _ret = r; \
  |  |  |  |  155|    838|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 838, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    838|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    610|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 610, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  157|    838|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    838|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    838|	return _ret; \
  |  |  |  |  163|    838|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2496|    838|}
card-openpgp.c:pgp_get_data:
 1991|  6.36k|{
 1992|  6.36k|	sc_apdu_t	apdu;
 1993|  6.36k|	int		r;
 1994|       |
 1995|  6.36k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.36k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.36k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.36k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.36k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.36k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1996|       |
 1997|  6.36k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, tag >> 8, tag);
  ------------------
  |  |  301|  6.36k|#define SC_APDU_CASE_2			0x22
  ------------------
 1998|  6.36k|	apdu.le = ((buf_len >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : buf_len;
  ------------------
  |  |  554|  4.53k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (1998:13): [True: 4.53k, False: 1.83k]
  |  Branch (1998:33): [True: 4.47k, False: 54]
  ------------------
 1999|  6.36k|	apdu.resp = buf;
 2000|  6.36k|	apdu.resplen = buf_len;
 2001|       |
 2002|  6.36k|	r = sc_transmit_apdu(card, &apdu);
 2003|  6.36k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  6.36k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.36k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.36k|	int _ret = (r); \
  |  |  |  |  168|  6.36k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 39, False: 6.32k]
  |  |  |  |  ------------------
  |  |  |  |  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|  6.36k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.32k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2004|       |
 2005|  6.32k|	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|  6.32k|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (2009:6): [True: 1.71k, False: 4.61k]
  ------------------
 2010|  1.71k|	    (tag == DO_CERT  ||
  ------------------
  |  |  138|  3.42k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (2010:7): [True: 258, False: 1.45k]
  ------------------
 2011|  1.45k|	     tag == DO_PRIV1 ||
  ------------------
  |  |  149|  3.16k|#define DO_PRIV1                 0x0101
  ------------------
  |  Branch (2011:7): [True: 20, False: 1.43k]
  ------------------
 2012|  1.43k|	     tag == DO_PRIV2 ||
  ------------------
  |  |  150|  3.14k|#define DO_PRIV2                 0x0102
  ------------------
  |  Branch (2012:7): [True: 22, False: 1.41k]
  ------------------
 2013|  1.41k|	     tag == DO_PRIV3 ||
  ------------------
  |  |  151|  3.12k|#define DO_PRIV3                 0x0103
  ------------------
  |  Branch (2013:7): [True: 22, False: 1.39k]
  ------------------
 2014|  1.39k|	     tag == DO_PRIV4)) {
  ------------------
  |  |  152|  1.39k|#define DO_PRIV4                 0x0104
  ------------------
  |  Branch (2014:7): [True: 22, False: 1.36k]
  ------------------
 2015|    344|		if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|    344|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (2015:7): [True: 1, False: 343]
  ------------------
 2016|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 2017|      1|			apdu.resplen = 0;
 2018|      1|		}
 2019|    344|	}
 2020|  6.32k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  6.32k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.32k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.32k|	int _ret = (r); \
  |  |  |  |  168|  6.32k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.85k, False: 2.47k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.85k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.85k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.85k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.85k|		return _ret; \
  |  |  |  |  172|  3.85k|	} \
  |  |  |  |  173|  6.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.47k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2021|       |
 2022|  2.47k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 909, False: 1.56k]
  |  |  |  |  ------------------
  |  |  |  |  156|    909|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 909]
  |  |  |  |  ------------------
  |  |  |  |  157|    909|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.56k|	} 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|  2.47k|	return _ret; \
  |  |  |  |  163|  2.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2023|  2.47k|}
card-openpgp.c:pgp_set_security_env:
 2539|    466|{
 2540|    466|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    466|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2541|       |
 2542|    466|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    466|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    466|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    466|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    466|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 466]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2543|       |
 2544|       |	/* The SC_SEC_ENV_ALG_PRESENT is set always so let it pass for GNUK */
 2545|    466|	if ((env->flags & SC_SEC_ENV_ALG_PRESENT)
  ------------------
  |  |   69|    466|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (2545:6): [True: 466, False: 0]
  ------------------
 2546|    466|		&& (env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   78|    466|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2546:6): [True: 0, False: 466]
  ------------------
 2547|      0|		&& (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (2547:6): [True: 0, False: 0]
  ------------------
 2548|      0|		&& (card->type != SC_CARD_TYPE_OPENPGP_GNUK))
  ------------------
  |  Branch (2548:6): [True: 0, False: 0]
  ------------------
 2549|    466|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2550|    466|				"only RSA algorithm supported");
 2551|       |
 2552|    466|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || (env->key_ref_len != 1))
  ------------------
  |  |   67|    466|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (2552:6): [True: 0, False: 466]
  |  Branch (2552:52): [True: 0, False: 466]
  ------------------
 2553|    466|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2554|    466|				"exactly one key reference required");
 2555|       |
 2556|    466|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
  ------------------
  |  |   66|    466|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (2556:6): [True: 0, False: 466]
  ------------------
 2557|    466|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2558|    466|			"passing file references not supported");
 2559|       |
 2560|    466|	sc_log(card->ctx, "Key ref %d", env->key_ref[0]);
  ------------------
  |  |   71|    466|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2561|    466|	switch (env->operation) {
 2562|    376|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   57|    376|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2562:2): [True: 376, False: 90]
  ------------------
 2563|    376|		sc_log(card->ctx, "Operation: Sign.");
  ------------------
  |  |   71|    376|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2564|    376|		if (env->key_ref[0] != 0x00 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2564:7): [True: 232, False: 144]
  |  Branch (2564:34): [True: 0, False: 232]
  ------------------
 2565|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2566|      0|				"Key reference not compatible with "
 2567|      0|				"requested usage");
 2568|      0|		}
 2569|    376|		break;
 2570|    376|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   56|     90|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2570:2): [True: 90, False: 376]
  ------------------
 2571|     90|		sc_log(card->ctx, "Operation: Decipher.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2572|       |		/* we allow key ref 2 (auth key) to be used for deciphering */
 2573|     90|		if (env->key_ref[0] != 0x01 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2573:7): [True: 12, False: 78]
  |  Branch (2573:34): [True: 0, False: 12]
  ------------------
 2574|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2575|      0|				"Key reference not compatible with "
 2576|      0|				"requested usage");
 2577|      0|		}
 2578|     90|		break;
 2579|     90|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   59|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2579:2): [True: 0, False: 466]
  ------------------
 2580|      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__
  |  |  ------------------
  ------------------
 2581|      0|		break;
 2582|      0|	default:
  ------------------
  |  Branch (2582:2): [True: 0, False: 466]
  ------------------
 2583|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2584|    466|				"invalid operation");
 2585|    466|	}
 2586|       |
 2587|    466|	priv->sec_env = *env;
 2588|       |
 2589|    466|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    466|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    466|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    466|	int _ret = r; \
  |  |  |  |  155|    466|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 466, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    466|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 466]
  |  |  |  |  ------------------
  |  |  |  |  157|    466|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    466|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    466|	return _ret; \
  |  |  |  |  163|    466|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2590|    466|}
card-openpgp.c:pgp_compute_signature:
 2644|    376|{
 2645|    376|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|    376|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2646|    376|	sc_security_env_t	*env = &priv->sec_env;
 2647|    376|	sc_apdu_t		apdu;
 2648|    376|	u8 apdu_case = (card->type == SC_CARD_TYPE_OPENPGP_GNUK)
  ------------------
  |  Branch (2648:17): [True: 87, False: 289]
  ------------------
 2649|    376|			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  294|     87|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  303|    665|#define SC_APDU_CASE_4			0x24
  ------------------
 2650|    376|	int			r;
 2651|       |
 2652|    376|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    376|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    376|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    376|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    376|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 376]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2653|       |
 2654|    376|	if (env->operation != SC_SEC_OPERATION_SIGN)
  ------------------
  |  |   57|    376|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2654:6): [True: 0, False: 376]
  ------------------
 2655|    376|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2656|    376|				"invalid operation");
 2657|       |
 2658|    376|	switch (env->key_ref[0]) {
 2659|    144|	case 0x00: /* signature key */
  ------------------
  |  Branch (2659:2): [True: 144, False: 232]
  ------------------
 2660|       |		/* PSO SIGNATURE */
 2661|    144|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x9E, 0x9A);
 2662|    144|		break;
 2663|    232|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2663:2): [True: 232, False: 144]
  ------------------
 2664|       |		/* INTERNAL AUTHENTICATE */
 2665|    232|		sc_format_apdu(card, &apdu, apdu_case, 0x88, 0, 0);
 2666|    232|		break;
 2667|      0|	case 0x01:
  ------------------
  |  Branch (2667:2): [True: 0, False: 376]
  ------------------
 2668|      0|	default:
  ------------------
  |  Branch (2668:2): [True: 0, False: 376]
  ------------------
 2669|       |		/* From PKCS #11 point of view, we should be able to use
 2670|       |		 * curve25519 to do digital signature, but it is not how it
 2671|       |		 * is used in OpenPGP so we will not allow it here */
 2672|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2673|    376|			"invalid key reference");
 2674|    376|	}
 2675|       |
 2676|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2677|    376|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  554|    376|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2677:6): [True: 370, False: 6]
  |  Branch (2677:52): [True: 87, False: 283]
  ------------------
 2678|     87|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     87|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2679|       |
 2680|    376|	apdu.lc = data_len;
 2681|    376|	apdu.data = (u8 *)data;
 2682|    376|	apdu.datalen = data_len;
 2683|    376|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  554|    376|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2683:13): [True: 376, False: 0]
  |  Branch (2683:32): [True: 370, False: 6]
  ------------------
 2684|    376|	apdu.resp    = out;
 2685|    376|	apdu.resplen = outlen;
 2686|       |
 2687|    376|	r = sc_transmit_apdu(card, &apdu);
 2688|    376|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    376|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    376|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    376|	int _ret = (r); \
  |  |  |  |  168|    376|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 152, False: 224]
  |  |  |  |  ------------------
  |  |  |  |  169|    152|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    152|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    152|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    152|		return _ret; \
  |  |  |  |  172|    152|	} \
  |  |  |  |  173|    376|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 224]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2689|       |
 2690|    224|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2691|    224|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|    224|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    224|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    224|	int _ret = (r); \
  |  |  |  |  168|    224|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 170, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  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|    224|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 54]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2692|       |
 2693|     54|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 32, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  156|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  157|     32|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|     22|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     22|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     22|	} \
  |  |  |  |  162|     54|	return _ret; \
  |  |  |  |  163|     54|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2694|     54|}
card-openpgp.c:pgp_decipher:
 2703|     74|{
 2704|     74|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     74|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2705|     74|	sc_security_env_t	*env = &priv->sec_env;
 2706|     74|	sc_apdu_t	apdu;
 2707|     74|	u8 apdu_case = SC_APDU_CASE_4;
  ------------------
  |  |  303|     74|#define SC_APDU_CASE_4			0x24
  ------------------
 2708|     74|	u8		*temp = NULL, *p = NULL;
 2709|     74|	size_t		templen, pklen, dolen;
 2710|     74|	int		r;
 2711|       |
 2712|     74|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     74|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2713|       |
 2714|       |	/* padding according to OpenPGP card spec 1.1 & 2.x section 7.2.9 / 3.x section 7.2.11
 2715|       |	 * The longest possible prefix is 10 bytes for ECDH */
 2716|     74|	templen = inlen + 10;
 2717|     74|	if (!(temp = malloc(templen)))
  ------------------
  |  Branch (2717:6): [True: 0, False: 74]
  ------------------
 2718|     74|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2719|       |
 2720|       |	/* padding byte: 0xa6 = ECC; 0x00 = RSA; 0x02 = AES */
 2721|     74|	switch (env->algorithm) {
 2722|     74|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|     74|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2722:2): [True: 74, False: 0]
  ------------------
 2723|       |		/* This is just PKCS#1.5 start byte and it should be already
 2724|       |		 * provided by the padding routines. But it lets put it here
 2725|       |		 * to make sure it does not conflict with following indicators */
 2726|     74|		temp[0] = 0x00;
 2727|     74|		memcpy(temp + 1, in, inlen);
 2728|     74|		inlen += 1;
 2729|     74|		break;
 2730|       |
 2731|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (2731:2): [True: 0, False: 74]
  ------------------
 2732|      0|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (2732:2): [True: 0, False: 74]
  ------------------
 2733|       |		/* Calculate length of External Public Key (0x86) */
 2734|      0|		r = sc_asn1_put_tag(0x86, NULL, inlen, NULL, 0, NULL);
 2735|      0|		if (r <= 0) {
  ------------------
  |  Branch (2735:7): [True: 0, False: 0]
  ------------------
 2736|      0|			free(temp);
 2737|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2738|      0|		}
 2739|      0|		pklen = r;
 2740|       |
 2741|       |		/* Calculate length of Public Key DO (0x7F49) */
 2742|      0|		r = sc_asn1_put_tag(0x7f49, NULL, pklen, NULL, 0, NULL);
 2743|      0|		if (r <= 0) {
  ------------------
  |  Branch (2743:7): [True: 0, False: 0]
  ------------------
 2744|      0|			free(temp);
 2745|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2746|      0|		}
 2747|      0|		dolen = r;
 2748|       |
 2749|      0|		p = temp;
 2750|       |		/* This is 0xA6 Cipher DO with associated length field */
 2751|      0|		r = sc_asn1_put_tag(0xA6, NULL, dolen, p, templen - (p - temp), &p);
 2752|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2752:7): [True: 0, False: 0]
  ------------------
 2753|      0|			free(temp);
 2754|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2755|      0|		}
 2756|       |
 2757|       |		/* Public Key DO (0x7F49) with associated length field */
 2758|      0|		r = sc_asn1_put_tag(0x7F49, NULL, pklen, p, templen - (p - temp), &p);
 2759|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2759:7): [True: 0, False: 0]
  ------------------
 2760|      0|			free(temp);
 2761|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2762|      0|		}
 2763|       |
 2764|       |		/* External Public Key (0x86) with associated length */
 2765|      0|		r = sc_asn1_put_tag(0x86, in, inlen, p, templen - (p - temp), &p);
 2766|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2766:7): [True: 0, False: 0]
  ------------------
 2767|      0|			free(temp);
 2768|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2769|      0|		}
 2770|      0|		inlen = (p - temp);
 2771|      0|		break;
 2772|      0|	case SC_ALGORITHM_AES:
  ------------------
  |  |   88|      0|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (2772:2): [True: 0, False: 74]
  ------------------
 2773|       |		/* not supported yet */
 2774|       |		/*
 2775|       |		temp[0] = 0x02;
 2776|       |		memcpy(temp + 1, in, inlen);
 2777|       |		inlen += 1;
 2778|       |		*/
 2779|       |		/* fall through */
 2780|      0|	default:
  ------------------
  |  Branch (2780:2): [True: 0, False: 74]
  ------------------
 2781|      0|		free(temp);
 2782|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2783|     74|	}
 2784|       |
 2785|     74|	in = temp;
 2786|       |
 2787|     74|	if (env->operation != SC_SEC_OPERATION_DECIPHER &&
  ------------------
  |  |   56|    148|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2787:6): [True: 0, False: 74]
  ------------------
 2788|      0|			env->operation != SC_SEC_OPERATION_DERIVE) {
  ------------------
  |  |   59|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2788:4): [True: 0, False: 0]
  ------------------
 2789|      0|		free(temp);
 2790|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2791|      0|				"invalid operation");
 2792|      0|	}
 2793|       |
 2794|     74|	switch (env->key_ref[0]) {
 2795|     64|	case 0x01: /* Decryption key */
  ------------------
  |  Branch (2795:2): [True: 64, False: 10]
  ------------------
 2796|     74|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2796:2): [True: 10, False: 64]
  ------------------
 2797|       |		/* PSO DECIPHER */
 2798|     74|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x80, 0x86);
 2799|     74|		break;
 2800|      0|	case 0x00: /* signature key */
  ------------------
  |  Branch (2800:2): [True: 0, False: 74]
  ------------------
 2801|      0|	default:
  ------------------
  |  Branch (2801:2): [True: 0, False: 74]
  ------------------
 2802|      0|		free(temp);
 2803|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2804|     74|				"invalid key reference");
 2805|     74|	}
 2806|       |
 2807|       |	/* Gnuk only supports short APDU, so we need to use command chaining */
 2808|     74|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (2808:6): [True: 15, False: 59]
  ------------------
 2809|     15|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     15|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2810|     15|	}
 2811|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2812|     74|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  554|     74|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2812:6): [True: 73, False: 1]
  |  Branch (2812:52): [True: 15, False: 58]
  ------------------
 2813|     15|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     15|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2814|       |
 2815|     74|	apdu.lc = inlen;
 2816|     74|	apdu.data = (u8 *)in;
 2817|     74|	apdu.datalen = inlen;
 2818|     74|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  554|     74|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2818:13): [True: 74, False: 0]
  |  Branch (2818:32): [True: 73, False: 1]
  ------------------
 2819|     74|	apdu.resp = out;
 2820|     74|	apdu.resplen = outlen;
 2821|       |
 2822|       |	/* For OpenPGP Card >=v3.3, key slot 3 instead of 2 can be used for deciphering,
 2823|       |	 * but this has to be set via MSE beforehand on every usage (slot 2 is used by default)
 2824|       |	 * see section 7.2.18 of the specification of OpenPGP Card v3.3 */
 2825|     74|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2825:6): [True: 57, False: 17]
  |  Branch (2825:47): [True: 10, False: 47]
  ------------------
 2826|     10|		pgp_set_MSE(card, 3, 0xb8);
 2827|     10|	}
 2828|       |
 2829|     74|	r = sc_transmit_apdu(card, &apdu);
 2830|     74|	free(temp);
 2831|     74|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 14, False: 60]
  |  |  |  |  ------------------
  |  |  |  |  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|     74|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 60]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2832|       |
 2833|     60|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2834|     60|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     60|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     60|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     60|	int _ret = (r); \
  |  |  |  |  168|     60|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 37, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  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|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2835|       |
 2836|       |	/* For OpenPGP Card >=v3.3, use key slot 2 for deciphering again (set to default) */
 2837|     23|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2837:6): [True: 18, False: 5]
  |  Branch (2837:47): [True: 4, False: 14]
  ------------------
 2838|      4|		pgp_set_MSE(card, 2, 0xb8);
 2839|      4|	}
 2840|       |
 2841|     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: 6, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  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|     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|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2842|     23|}
card-openpgp.c:pgp_set_MSE:
 2605|     14|{
 2606|     14|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     14|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2607|     14|	sc_apdu_t	apdu;
 2608|     14|	u8	apdu_case = SC_APDU_CASE_3;
  ------------------
  |  |  302|     14|#define SC_APDU_CASE_3			0x23
  ------------------
 2609|     14|	u8	apdu_data[3];
 2610|     14|	int	r;
 2611|       |
 2612|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2613|       |
 2614|       |	// check if MSE is supported
 2615|     14|	if (!(priv->ext_caps & EXT_CAP_MSE))
  ------------------
  |  Branch (2615:6): [True: 0, False: 14]
  ------------------
 2616|     14|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2617|       |
 2618|       |	// create apdu
 2619|     14|	sc_format_apdu(card, &apdu, apdu_case, 0x22, 0x41, p2);
 2620|     14|	apdu.lc = 3;
 2621|     14|	apdu_data[0] = 0x83;
 2622|     14|	apdu_data[1] = 0x01;
 2623|     14|	apdu_data[2] = key;
 2624|     14|	apdu.data = apdu_data;
 2625|     14|	apdu.datalen = 3;
 2626|       |
 2627|       |	// transmit apdu
 2628|     14|	r = sc_transmit_apdu(card, &apdu);
 2629|     14|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2630|       |
 2631|     11|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2632|     11|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     11|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     11|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     11|	int _ret = (r); \
  |  |  |  |  168|     11|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2633|       |
 2634|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2635|      3|}
card-openpgp.c:pgp_card_ctl:
 4011|    284|{
 4012|    284|	int r;
 4013|       |
 4014|    284|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    284|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    284|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    284|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    284|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 284]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4015|       |
 4016|    284|	switch(cmd) {
  ------------------
  |  Branch (4016:9): [True: 284, False: 0]
  ------------------
 4017|     27|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4017:2): [True: 27, False: 257]
  ------------------
 4018|     27|		memmove((sc_serial_number_t *) ptr, &card->serialnr, sizeof(card->serialnr));
 4019|     27|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     27|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     27|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     27|	int _ret = r; \
  |  |  |  |  155|     27|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 27, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     27|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 27]
  |  |  |  |  ------------------
  |  |  |  |  157|     27|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     27|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     27|	return _ret; \
  |  |  |  |  163|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4020|      0|		break;
 4021|    257|	case SC_CARDCTL_OPENPGP_SELECT_DATA:
  ------------------
  |  Branch (4021:2): [True: 257, False: 27]
  ------------------
 4022|    257|		r = pgp_select_data(card, *((u8 *) ptr));
 4023|    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|    242|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 242, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4024|      0|		break;
 4025|      0|#ifdef ENABLE_OPENSSL
 4026|      0|	case SC_CARDCTL_OPENPGP_GENERATE_KEY:
  ------------------
  |  Branch (4026:2): [True: 0, False: 284]
  ------------------
 4027|      0|		r = pgp_gen_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4028|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4029|      0|		break;
 4030|      0|	case SC_CARDCTL_OPENPGP_STORE_KEY:
  ------------------
  |  Branch (4030:2): [True: 0, False: 284]
  ------------------
 4031|      0|		r = pgp_store_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4032|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4033|      0|		break;
 4034|      0|#endif /* ENABLE_OPENSSL */
 4035|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (4035:2): [True: 0, False: 284]
  ------------------
 4036|      0|		r = pgp_erase_card(card);
 4037|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4038|      0|		break;
 4039|    284|	}
 4040|       |
 4041|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4042|      0|}
card-openpgp.c:pgp_select_data:
 1953|    257|{
 1954|    257|	sc_apdu_t	apdu;
 1955|    257|	u8	apdu_data[6];
 1956|    257|	int	r;
 1957|    257|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    257|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1958|       |
 1959|    257|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    257|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    257|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    257|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    257|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 257]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1960|       |
 1961|    257|	if (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (1961:6): [True: 158, False: 99]
  ------------------
 1962|    257|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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|    158|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 158, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1963|       |
 1964|     99|	sc_log(card->ctx, "select data with: %u", p1);
  ------------------
  |  |   71|     99|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1965|       |
 1966|       |	// create apdu data (taken from spec: SELECT DATA 7.2.5.)
 1967|     99|	apdu_data[0] = 0x60;
 1968|     99|	apdu_data[1] = 0x04;
 1969|     99|	apdu_data[2] = 0x5c;
 1970|     99|	apdu_data[3] = 0x02;
 1971|     99|	apdu_data[4] = 0x7f;
 1972|     99|	apdu_data[5] = 0x21;
 1973|       |
 1974|       |	// apdu, cla, ins, p1, p2, data, datalen, resp, resplen
 1975|     99|	sc_format_apdu_ex(&apdu, 0x00, 0xA5, p1, 0x04, apdu_data, sizeof(apdu_data), NULL, 0);
 1976|       |
 1977|       |	// transmit apdu
 1978|     99|	r = sc_transmit_apdu(card, &apdu);
 1979|     99|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     99|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     99|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     99|	int _ret = (r); \
  |  |  |  |  168|     99|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 98]
  |  |  |  |  ------------------
  |  |  |  |  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|     99|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 98]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1980|     98|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1981|     98|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 83, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  169|     83|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     83|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     83|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     83|		return _ret; \
  |  |  |  |  172|     83|	} \
  |  |  |  |  173|     98|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1982|     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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1983|     15|}
card-openpgp.c:pgp_card_reader_lock_obtained:
 4171|  10.2k|{
 4172|  10.2k|	struct pgp_priv_data *priv = DRVDATA(card); /* may be null during initialization */
  ------------------
  |  |  189|  10.2k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 4173|  10.2k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  10.2k|#define SC_SUCCESS				0
  ------------------
 4174|       |
 4175|  10.2k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.2k]
  |  |  ------------------
  ------------------
 4176|       |
 4177|  10.2k|	if (card->flags & SC_CARD_FLAG_KEEP_ALIVE
  ------------------
  |  |  544|  20.4k|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  |  Branch (4177:6): [True: 0, False: 10.2k]
  ------------------
 4178|      0|			&& was_reset <= 0
  ------------------
  |  Branch (4178:7): [True: 0, False: 0]
  ------------------
 4179|      0|			&& priv != NULL && priv->mf && priv->mf->file) {
  ------------------
  |  Branch (4179:7): [True: 0, False: 0]
  |  Branch (4179:23): [True: 0, False: 0]
  |  Branch (4179:35): [True: 0, False: 0]
  ------------------
 4180|       |		/* check whether applet is still selected */
 4181|      0|		unsigned char aid[16];
 4182|       |
 4183|      0|		r = sc_get_data(card, 0x004F, aid, sizeof aid);
 4184|      0|		if ((size_t) r != priv->mf->file->namelen
  ------------------
  |  Branch (4184:7): [True: 0, False: 0]
  ------------------
 4185|      0|				|| 0 != memcmp(aid, priv->mf->file->name, r)) {
  ------------------
  |  Branch (4185:8): [True: 0, False: 0]
  ------------------
 4186|       |			/* reselect is required */
 4187|      0|			was_reset = 1;
 4188|      0|		}
 4189|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 4190|      0|	}
 4191|       |
 4192|  10.2k|	if (was_reset > 0) {
  ------------------
  |  Branch (4192:6): [True: 0, False: 10.2k]
  ------------------
 4193|      0|		sc_file_t	*file = NULL;
 4194|      0|		sc_path_t	path;
 4195|       |		/* select application "OpenPGP" */
 4196|      0|		sc_format_path("D276:0001:2401", &path);
 4197|      0|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 4198|      0|		r = iso_ops->select_file(card, &path, &file);
 4199|      0|		sc_file_free(file);
 4200|      0|	}
 4201|       |
 4202|  10.2k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  10.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.2k|	int _ret = r; \
  |  |  |  |  155|  10.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 10.2k]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.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|  10.2k|	return _ret; \
  |  |  |  |  163|  10.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4203|  10.2k|}

sc_get_piv_driver:
 6476|  16.4k|{
 6477|  16.4k|	return sc_get_driver();
 6478|  16.4k|}
card-piv.c:sc_get_driver:
 6449|  16.4k|{
 6450|  16.4k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6451|       |
 6452|  16.4k|	piv_ops = *iso_drv->ops;
 6453|  16.4k|	piv_ops.match_card = piv_match_card;
 6454|  16.4k|	piv_ops.init = piv_init;
 6455|  16.4k|	piv_ops.finish = piv_finish;
 6456|       |
 6457|  16.4k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6458|  16.4k|	piv_ops.get_challenge = piv_get_challenge;
 6459|  16.4k|	piv_ops.logout = piv_logout;
 6460|  16.4k|	piv_ops.read_binary = piv_read_binary;
 6461|  16.4k|	piv_ops.write_binary = piv_write_binary;
 6462|  16.4k|	piv_ops.set_security_env = piv_set_security_env;
 6463|  16.4k|	piv_ops.restore_security_env = piv_restore_security_env;
 6464|  16.4k|	piv_ops.compute_signature = piv_compute_signature;
 6465|  16.4k|	piv_ops.decipher = piv_decipher;
 6466|  16.4k|	piv_ops.check_sw = piv_check_sw;
 6467|  16.4k|	piv_ops.card_ctl = piv_card_ctl;
 6468|  16.4k|	piv_ops.pin_cmd = piv_pin_cmd;
 6469|  16.4k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6470|       |
 6471|  16.4k|	return &piv_drv;
 6472|  16.4k|}
card-piv.c:piv_match_card:
 5413|  5.60k|{
 5414|  5.60k|	int r = 0;
 5415|       |
 5416|  5.60k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  5.60k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5417|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5418|       |	/* user provided card type must be one we know */
 5419|  5.60k|	switch (card->type) {
 5420|  5.60k|	case -1:
  ------------------
  |  Branch (5420:2): [True: 5.60k, False: 0]
  ------------------
 5421|  5.60k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5421:2): [True: 0, False: 5.60k]
  ------------------
 5422|  5.60k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5422:2): [True: 0, False: 5.60k]
  ------------------
 5423|  5.60k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5423:2): [True: 0, False: 5.60k]
  ------------------
 5424|  5.60k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5424:2): [True: 0, False: 5.60k]
  ------------------
 5425|  5.60k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5425:2): [True: 0, False: 5.60k]
  ------------------
 5426|  5.60k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5426:2): [True: 0, False: 5.60k]
  ------------------
 5427|  5.60k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5427:2): [True: 0, False: 5.60k]
  ------------------
 5428|  5.60k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5428:2): [True: 0, False: 5.60k]
  ------------------
 5429|  5.60k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5429:2): [True: 0, False: 5.60k]
  ------------------
 5430|  5.60k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5430:2): [True: 0, False: 5.60k]
  ------------------
 5431|  5.60k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5431:2): [True: 0, False: 5.60k]
  ------------------
 5432|  5.60k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5432:2): [True: 0, False: 5.60k]
  ------------------
 5433|  5.60k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5433:2): [True: 0, False: 5.60k]
  ------------------
 5434|  5.60k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5434:2): [True: 0, False: 5.60k]
  ------------------
 5435|  5.60k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5435:2): [True: 0, False: 5.60k]
  ------------------
 5436|  5.60k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5436:2): [True: 0, False: 5.60k]
  ------------------
 5437|  5.60k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5437:2): [True: 0, False: 5.60k]
  ------------------
 5438|  5.60k|		break;
 5439|      0|	default:
  ------------------
  |  Branch (5439:2): [True: 0, False: 5.60k]
  ------------------
 5440|      0|		return 0; /* can not handle the card */
 5441|  5.60k|	}
 5442|       |
 5443|  5.60k|	r = sc_lock(card);
 5444|  5.60k|	if (r < 0)
  ------------------
  |  Branch (5444:6): [True: 0, False: 5.60k]
  ------------------
 5445|      0|		return 0;
 5446|       |	/* its one we know, or we can test for it in piv_init */
 5447|  5.60k|	r = piv_match_card_continued(card);
 5448|  5.60k|	sc_unlock(card);
 5449|       |
 5450|  5.60k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5450:6): [True: 4.64k, False: 957]
  |  Branch (5450:15): [True: 0, False: 957]
  ------------------
 5451|       |		/* clean up what we left in card */
 5452|  4.64k|		piv_finish(card);
 5453|  4.64k|		return 0; /* match failed */
 5454|  4.64k|	}
 5455|       |
 5456|    957|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|    957|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5457|    957|	return 1; /* matched */
 5458|  5.60k|}
card-piv.c:piv_match_card_continued:
 5462|  5.60k|{
 5463|  5.60k|	int i, r = 0, r2 = 0;
 5464|  5.60k|	int type = -1;
 5465|  5.60k|	piv_private_data_t *priv = NULL;
 5466|  5.60k|	int saved_type = card->type;
 5467|  5.60k|	sc_apdu_t apdu;
 5468|  5.60k|	u8 yubico_version_buf[3] = {0};
 5469|       |
 5470|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5471|       |	/* User provided card type must be one we know */
 5472|       |
 5473|  5.60k|	switch (card->type) {
 5474|  5.60k|	case -1:
  ------------------
  |  Branch (5474:2): [True: 5.60k, False: 0]
  ------------------
 5475|  5.60k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5475:2): [True: 0, False: 5.60k]
  ------------------
 5476|  5.60k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5476:2): [True: 0, False: 5.60k]
  ------------------
 5477|  5.60k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5477:2): [True: 0, False: 5.60k]
  ------------------
 5478|  5.60k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5478:2): [True: 0, False: 5.60k]
  ------------------
 5479|  5.60k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5479:2): [True: 0, False: 5.60k]
  ------------------
 5480|  5.60k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5480:2): [True: 0, False: 5.60k]
  ------------------
 5481|  5.60k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5481:2): [True: 0, False: 5.60k]
  ------------------
 5482|  5.60k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5482:2): [True: 0, False: 5.60k]
  ------------------
 5483|  5.60k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5483:2): [True: 0, False: 5.60k]
  ------------------
 5484|  5.60k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5484:2): [True: 0, False: 5.60k]
  ------------------
 5485|  5.60k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5485:2): [True: 0, False: 5.60k]
  ------------------
 5486|  5.60k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5486:2): [True: 0, False: 5.60k]
  ------------------
 5487|  5.60k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5487:2): [True: 0, False: 5.60k]
  ------------------
 5488|  5.60k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5488:2): [True: 0, False: 5.60k]
  ------------------
 5489|  5.60k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5489:2): [True: 0, False: 5.60k]
  ------------------
 5490|  5.60k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5490:2): [True: 0, False: 5.60k]
  ------------------
 5491|  5.60k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5491:2): [True: 0, False: 5.60k]
  ------------------
 5492|  5.60k|		type = card->type;
 5493|  5.60k|		break;
 5494|      0|	default:
  ------------------
  |  Branch (5494:2): [True: 0, False: 5.60k]
  ------------------
 5495|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5496|  5.60k|	}
 5497|  5.60k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.60k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5498|  5.60k|	if (type == -1) {
  ------------------
  |  Branch (5498:6): [True: 5.60k, False: 0]
  ------------------
 5499|       |		/*
 5500|       |		 * Try to identify card by ATR or historical data in ATR
 5501|       |		 * currently all PIV card will respond to piv_find_aid
 5502|       |		 * the same. But in future may need to know card type first,
 5503|       |		 * so do it here.
 5504|       |		 */
 5505|       |
 5506|  5.60k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5506:7): [True: 2.41k, False: 3.18k]
  ------------------
 5507|  2.41k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5507:8): [True: 469, False: 1.95k]
  ------------------
 5508|    469|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5508:6): [True: 175, False: 294]
  ------------------
 5509|    175|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5510|  2.24k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5510:15): [True: 1.53k, False: 709]
  ------------------
 5511|  1.53k|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5511:6): [True: 333, False: 1.20k]
  ------------------
 5512|    333|				type = SC_CARD_TYPE_PIV_II_NEO;
 5513|  1.91k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5513:15): [True: 1.23k, False: 681]
  ------------------
 5514|  1.23k|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5514:6): [True: 90, False: 1.14k]
  ------------------
 5515|     90|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5516|  1.82k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5516:15): [True: 1.14k, False: 681]
  ------------------
 5517|  1.14k|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5517:6): [True: 9, False: 1.13k]
  ------------------
 5518|      9|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5519|      9|			}
 5520|       |			/* look for TLV historic data */
 5521|  1.81k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5521:13): [True: 1.78k, False: 30]
  ------------------
 5522|  1.78k|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5522:6): [True: 612, False: 1.17k]
  ------------------
 5523|    612|				size_t datalen;
 5524|    612|				const u8 *data;
 5525|       |
 5526|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5527|    612|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5527:9): [True: 40, False: 572]
  ------------------
 5528|    612|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5529|     40|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5529:10): [True: 29, False: 11]
  |  Branch (5529:26): [True: 13, False: 16]
  ------------------
 5530|     13|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5531|     27|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5531:17): [True: 5, False: 22]
  |  Branch (5531:33): [True: 1, False: 4]
  ------------------
 5532|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5533|      1|					}
 5534|       |					/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
 5535|       |					 * https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
 5536|       |					 * On Windows 10, using Omnikey 5021, the ATR is correct
 5537|       |					 * will look at only 6 bytes that do match
 5538|       |					 */
 5539|     26|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5539:15): [True: 4, False: 22]
  |  Branch (5539:31): [True: 1, False: 3]
  ------------------
 5540|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5541|      1|					}
 5542|    572|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5542:16): [True: 187, False: 385]
  ------------------
 5543|    572|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5544|    187|					int k;
 5545|       |
 5546|    314|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5546:18): [True: 251, False: 63]
  ------------------
 5547|    251|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5547:11): [True: 235, False: 16]
  ------------------
 5548|    235|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5548:9): [True: 124, False: 111]
  ------------------
 5549|    124|							type = SC_CARD_TYPE_PIV_II_HIST;
 5550|    124|							break;
 5551|    124|						}
 5552|    251|					}
 5553|    187|				}
 5554|    612|			}
 5555|  2.41k|		}
 5556|       |
 5557|  5.60k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.60k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5558|       |
 5559|  5.60k|		if (type == -1) {
  ------------------
  |  Branch (5559:7): [True: 4.85k, False: 746]
  ------------------
 5560|       |			/* use known ATRs  which changes the type */
 5561|  4.85k|			i = _sc_match_atr(card, piv_atrs, &type);
 5562|  4.85k|			if (i < 0)
  ------------------
  |  Branch (5562:8): [True: 4.82k, False: 35]
  ------------------
 5563|  4.82k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5564|  4.85k|		}
 5565|  5.60k|	}
 5566|       |
 5567|  5.60k|	card->type = type;
 5568|       |
 5569|       |	/* we either found via ATR historic bytes or ATR directly */
 5570|  5.60k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.60k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5571|       |
 5572|       |	/* allocate and init basic fields */
 5573|  5.60k|	priv = calloc(1, sizeof(piv_private_data_t));
 5574|       |
 5575|  5.60k|	if (!priv)
  ------------------
  |  Branch (5575:6): [True: 0, False: 5.60k]
  ------------------
 5576|  5.60k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5577|       |
 5578|  5.60k|	card->drv_data = priv; /* will free if no match, or pass on to piv_init */
 5579|       |	/*
 5580|       |	 * Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
 5581|       |	 * If for some reason future cards have larger objects, this value needs to
 5582|       |	 * be increased here.
 5583|       |	 */
 5584|  5.60k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  229|  5.60k|#define MAX_FILE_SIZE 65535
  ------------------
 5585|  5.60k|	priv->selected_obj = -1;
 5586|  5.60k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5587|  5.60k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|  5.60k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5588|  5.60k|	priv->pstate = PIV_STATE_MATCH;
 5589|       |
 5590|       |#ifdef ENABLE_PIV_SM
 5591|       |	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
 5592|       |	card->sm_ctx.ops.open = piv_sm_open;
 5593|       |	card->sm_ctx.ops.get_sm_apdu = piv_get_sm_apdu;
 5594|       |	card->sm_ctx.ops.free_sm_apdu = piv_free_sm_apdu;
 5595|       |	card->sm_ctx.ops.close = piv_sm_close;
 5596|       |#endif /* ENABLE_PIV_SM */
 5597|       |
 5598|       |	/* See if contactless  or run as virtual card */
 5599|       |	/* PivApplet in .github/test_piv.sh for example */
 5600|  5.60k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5600:6): [True: 2.72k, False: 2.88k]
  ------------------
 5601|  2.72k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5601:4): [True: 2.43k, False: 282]
  ------------------
 5602|  2.43k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5602:4): [True: 198, False: 2.24k]
  ------------------
 5603|    198|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5603:4): [True: 129, False: 69]
  ------------------
 5604|    129|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5604:4): [True: 107, False: 22]
  ------------------
 5605|    107|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  382|    107|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5606|    107|	}
 5607|       |
 5608|   341k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5608:14): [True: 336k, False: 5.60k]
  ------------------
 5609|   336k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  638|   336k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5609:7): [True: 112k, False: 224k]
  ------------------
 5610|   112k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|   117k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5611|       |	/*
 5612|       |	 * Detect if active AID is PIV. NIST 800-73 says only one PIV application per card
 5613|       |	 * and PIV must be the default application.
 5614|       |	 * Try to avoid doing a select_aid and losing the login state on some cards.
 5615|       |	 * We may get interference on some cards by other drivers trying SELECT_AID before
 5616|       |	 * we get to see if PIV application is still active. Putting PIV driver first might help.
 5617|       |	 *
 5618|       |	 * Discovery Object introduced in 800-73-3 so will return OK if found and PIV applet active.
 5619|       |	 * Will fail with SC_ERROR_FILE_NOT_FOUND if 800-73-3 and no Discovery object.
 5620|       |	 * But some other card could also return SC_ERROR_FILE_NOT_FOUND.
 5621|       |	 * Will fail for other reasons if wrong applet is selected or bad PIV implementation.
 5622|       |	 */
 5623|       |
 5624|       |	/*
 5625|       |	 * if ATR matched or user forced card type
 5626|       |	 * test if PIV is active applet without using AID If fails try AID
 5627|       |	 */
 5628|       |
 5629|  5.60k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5629:6): [True: 781, False: 4.82k]
  ------------------
 5630|    781|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  382|    781|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5630:4): [True: 779, False: 2]
  ------------------
 5631|    779|		r = piv_find_discovery(card);
 5632|    779|		if (r < 0) {
  ------------------
  |  Branch (5632:7): [True: 461, False: 318]
  ------------------
 5633|    461|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5634|    461|			r = piv_find_aid(card);
 5635|    461|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  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: 125, False: 336]
  |  |  |  |  ------------------
  |  |  |  |  179|    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
  |  |  |  |  ------------------
  |  |  |  |  180|    125|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    125|		goto err; \
  |  |  |  |  182|    125|	} \
  |  |  |  |  183|    461|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 336]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5636|    461|		}
 5637|  4.82k|	} else {
 5638|       |		/* piv_find_aid saves al_label from response */
 5639|  4.82k|		r = piv_find_aid(card);
 5640|  4.82k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  4.82k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.82k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.82k|	int _ret = (r); \
  |  |  |  |  178|  4.82k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.52k, False: 303]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.52k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.52k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  4.52k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  4.52k|		goto err; \
  |  |  |  |  182|  4.52k|	} \
  |  |  |  |  183|  4.82k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 303]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5641|  4.82k|	}
 5642|       |
 5643|       |	/* Know to be PIV card but not the type */
 5644|       |
 5645|       |	/* If card type still unknown, see if Application Label is known and set card->type */
 5646|    957|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5646:6): [True: 9, False: 948]
  |  Branch (5646:24): [True: 7, False: 2]
  ------------------
 5647|      7|		switch (card->type) {
  ------------------
  |  Branch (5647:11): [True: 6, False: 1]
  ------------------
 5648|      6|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5648:3): [True: 6, False: 1]
  ------------------
 5649|      6|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5649:3): [True: 0, False: 7]
  ------------------
 5650|     11|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5650:16): [True: 6, False: 5]
  ------------------
 5651|      6|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5651:9): [True: 5, False: 1]
  ------------------
 5652|      5|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5652:7): [True: 1, False: 4]
  ------------------
 5653|      1|					sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "AL match i:%d type:%d", i, al_map[i].al_type);
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5654|      1|					card->type = al_map[i].al_type;
 5655|      1|					break;
 5656|      1|				}
 5657|      6|			}
 5658|      6|			break;
 5659|      7|		}
 5660|      7|	}
 5661|       |
 5662|    957|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d  CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    957|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5663|    957|			card->type, priv->card_issues, r, priv->alg_ids);
 5664|       |
 5665|       |	/*
 5666|       |	 * Assumes all Yubikey/Nitrokey/Token2/PivApplet cards are all "Yubico like"
 5667|       |	 * via ATR, ATR Historic bytes or Application Label
 5668|       |	 * Will also check if BASE cards are Yubikey like card and return a version number
 5669|       |	 * SC_CARD_TYPE_PIV_II_GENERIC can be set by user to not test for Yubico version
 5670|       |	 */
 5671|    957|	switch (card->type) {
  ------------------
  |  Branch (5671:10): [True: 761, False: 196]
  ------------------
 5672|    287|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5672:2): [True: 287, False: 670]
  ------------------
 5673|    445|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5673:2): [True: 158, False: 799]
  ------------------
 5674|    457|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5674:2): [True: 12, False: 945]
  ------------------
 5675|    458|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5675:2): [True: 1, False: 956]
  ------------------
 5676|    459|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5676:2): [True: 1, False: 956]
  ------------------
 5677|    459|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5677:2): [True: 0, False: 957]
  ------------------
 5678|    761|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5678:2): [True: 302, False: 655]
  ------------------
 5679|    761|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|    761|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5680|    761|		apdu.lc = 0;
 5681|    761|		apdu.data = NULL;
 5682|    761|		apdu.datalen = 0;
 5683|    761|		apdu.resp = yubico_version_buf;
 5684|    761|		apdu.resplen = sizeof(yubico_version_buf);
 5685|    761|		apdu.le = apdu.resplen;
 5686|    761|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5687|    761|		if (apdu.resplen == 3) {
  ------------------
  |  Branch (5687:7): [True: 412, False: 349]
  ------------------
 5688|    412|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5689|    412|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   71|    412|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5690|    412|		}
 5691|    761|		break;
 5692|    957|	}
 5693|       |
 5694|    957|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    957|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5695|    957|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5696|       |
 5697|       |	/* We now know PIV AID is active, test CCC object. 800-73-* say CCC is required */
 5698|       |	/* CCC not readable over contactless, unless using VCI. but dont need CCC for SC_CARD_TYPE_PIV_II_800_73_4 */
 5699|    957|	switch (card->type) {
  ------------------
  |  Branch (5699:10): [True: 431, False: 526]
  ------------------
 5700|       |	/*
 5701|       |	 * For cards that may also be CAC, try and read the CCC
 5702|       |	 * CCC is required and all Dual PIV/CAC will have a CCC
 5703|       |	 * Currently Dual PIV/CAC are based on NIST 800-73-1 which does not have Discovery or History
 5704|       |	 */
 5705|    302|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5705:2): [True: 302, False: 655]
  ------------------
 5706|    302|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5706:2): [True: 0, False: 957]
  ------------------
 5707|    425|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5707:2): [True: 123, False: 834]
  ------------------
 5708|    425|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5708:2): [True: 0, False: 957]
  ------------------
 5709|    425|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5709:2): [True: 0, False: 957]
  ------------------
 5710|    431|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5710:2): [True: 6, False: 951]
  ------------------
 5711|    431|		r2 = piv_process_ccc(card);
 5712|    431|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    431|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5713|    431|				card->type, r2, priv->card_issues, r, priv->alg_ids);
 5714|       |		/* Ignore any error. */
 5715|       |		/* If CCC says it has CAC with PKI on card set to one of the SC_CARD_TYPE_PIV_II_*_DUAL_CAC */
 5716|    431|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  171|    431|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5716:7): [True: 6, False: 425]
  ------------------
 5717|      6|			switch (card->type) {
  ------------------
  |  Branch (5717:12): [True: 6, False: 0]
  ------------------
 5718|      1|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5718:4): [True: 1, False: 5]
  ------------------
 5719|      1|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5719:4): [True: 0, False: 6]
  ------------------
 5720|      5|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5720:4): [True: 4, False: 2]
  ------------------
 5721|      5|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5721:4): [True: 0, False: 6]
  ------------------
 5722|      5|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5723|      5|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|      5|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5724|      5|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      5|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5725|      5|				break;
 5726|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5726:4): [True: 0, False: 6]
  ------------------
 5727|      0|				card->type = SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC;
 5728|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5729|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5730|      0|				break;
 5731|      1|			case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5731:4): [True: 1, False: 5]
  ------------------
 5732|      1|				card->type = SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC;
 5733|      1|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|      1|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5734|      1|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      1|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5735|      1|				break;
 5736|      6|			}
 5737|      6|		}
 5738|    431|		break;
 5739|       |
 5740|    431|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5740:2): [True: 0, False: 957]
  ------------------
 5741|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5741:2): [True: 0, False: 957]
  ------------------
 5742|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5742:2): [True: 0, False: 957]
  ------------------
 5743|      0|		priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5744|      0|		priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5745|      0|		break;
 5746|    957|	}
 5747|    957|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    957|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5748|    957|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5749|       |
 5750|       |	/* If contactless or run as virtual card try to get alg refs from AC entries in response to SELECT AID */
 5751|    957|	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  377|    957|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
              	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  382|    318|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5751:6): [True: 318, False: 639]
  |  Branch (5751:51): [True: 0, False: 318]
  ------------------
 5752|      0|		r2 = piv_find_aid(card);
 5753|      0|	}
 5754|       |
 5755|       |	/* Read AID if needed for these cards types */
 5756|    957|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  377|    957|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5756:6): [True: 318, False: 639]
  ------------------
 5757|    318|		switch (card->type) {
  ------------------
  |  Branch (5757:11): [True: 13, False: 305]
  ------------------
 5758|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5758:3): [True: 0, False: 318]
  ------------------
 5759|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5759:3): [True: 0, False: 318]
  ------------------
 5760|      0|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5760:3): [True: 0, False: 318]
  ------------------
 5761|     12|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5761:3): [True: 12, False: 306]
  ------------------
 5762|     13|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5762:3): [True: 1, False: 317]
  ------------------
 5763|     13|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5763:3): [True: 0, False: 318]
  ------------------
 5764|     13|			r2 = piv_find_aid(card);
 5765|    318|		}
 5766|    318|	}
 5767|       |
 5768|    957|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    957|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5769|    957|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5770|       |
 5771|       |	/* if card did not specify any of the NIST basic alg_ids add them */
 5772|    957|	if ((priv->alg_ids & AI_NIST) == 0) {
  ------------------
  |  |  601|    957|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  592|    957|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  593|    957|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  594|    957|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  596|    957|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  597|    957|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
  |  Branch (5772:6): [True: 955, False: 2]
  ------------------
 5773|    955|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  601|    955|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  592|    955|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  593|    955|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  594|    955|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  596|    955|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  597|    955|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 5774|    955|	}
 5775|       |
 5776|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 5777|    957|	switch (card->type) {
  ------------------
  |  Branch (5777:10): [True: 301, False: 656]
  ------------------
 5778|    301|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5778:2): [True: 301, False: 656]
  ------------------
 5779|    301|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5779:2): [True: 0, False: 957]
  ------------------
 5780|    301|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  378|    301|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (5780:7): [True: 0, False: 301]
  ------------------
 5781|      0|			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5782|      0|		}
 5783|       |
 5784|       |#ifdef ENABLE_PIV_SM
 5785|       |		/* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
 5786|       |		if ((priv->pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC)) != 0) {
 5787|       |			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5788|       |		}
 5789|       |#endif
 5790|    301|		break;
 5791|    957|	}
 5792|       |
 5793|    957|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    957|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5794|    957|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5795|       |
 5796|       |	/*
 5797|       |	 * Set card_issues flags based card->type and version numbers if available.
 5798|       |	 *
 5799|       |	 * YubiKey NEO, Yubikey 4 and other devices with PIV applets, have compliance
 5800|       |	 * issues with the NIST 800-73-3 specs. The OpenSC developers do not have
 5801|       |	 * access to all the different devices or versions of the devices.
 5802|       |	 * Vendor and user input is welcome on any compliance issues.
 5803|       |	 *
 5804|       |	 * For the Yubico devices The assumption is also made that if a bug is
 5805|       |	 * fixed in a Yubico version that means it is fixed on both NEO and Yubikey 4.
 5806|       |	 *
 5807|       |	 * The flags CI_CANT_USE_GETDATA_FOR_STATE and CI_DISCOVERY_USELESS
 5808|       |	 * may be set earlier or later then in the following code.
 5809|       |	 */
 5810|       |
 5811|    957|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    957|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5812|    957|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5813|    957|	switch (card->type) {
 5814|    287|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5814:2): [True: 287, False: 670]
  ------------------
 5815|    287|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  588|    287|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 5816|    287|				     CI_VERIFY_630X |
  ------------------
  |  |  576|    287|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 5817|    287|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  585|    287|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5818|    287|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  581|    287|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5819|    287|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  586|    287|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 5820|    287|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5820:7): [True: 192, False: 95]
  ------------------
 5821|    192|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  577|    192|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5822|    287|		break;
 5823|       |
 5824|    158|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5824:2): [True: 158, False: 799]
  ------------------
 5825|    159|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5825:2): [True: 1, False: 956]
  ------------------
 5826|    160|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5826:2): [True: 1, False: 956]
  ------------------
 5827|    160|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  585|    160|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5828|    160|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  581|    160|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5829|    160|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5829:7): [True: 48, False: 112]
  ------------------
 5830|     48|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  577|     48|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5831|    160|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (5831:7): [True: 109, False: 51]
  ------------------
 5832|    109|			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  595|    109|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  598|    109|#define AI_25519			    0x00100000U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  599|    109|#define AI_X25519			    0x00200000U
  ------------------
 5833|    160|		break;
 5834|       |
 5835|     12|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5835:2): [True: 12, False: 945]
  ------------------
 5836|     12|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  585|     12|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5837|     12|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (5837:7): [True: 6, False: 6]
  ------------------
 5838|      6|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  595|      6|#define AI_RSA_4096			    0x00000008U
  ------------------
 5839|     12|		break;
 5840|       |
 5841|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5841:2): [True: 0, False: 957]
  ------------------
 5842|      5|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5842:2): [True: 5, False: 952]
  ------------------
 5843|      5|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5843:2): [True: 0, False: 957]
  ------------------
 5844|      5|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5844:2): [True: 0, False: 957]
  ------------------
 5845|      5|		priv->card_issues |= 0; /* could add others here */
 5846|      5|		break;
 5847|       |
 5848|    301|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5848:2): [True: 301, False: 656]
  ------------------
 5849|    420|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5849:2): [True: 119, False: 838]
  ------------------
 5850|    420|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5850:2): [True: 0, False: 957]
  ------------------
 5851|    420|		priv->card_issues |= 0; /* could add others here */
 5852|    420|		break;
 5853|       |
 5854|      5|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5854:2): [True: 5, False: 952]
  ------------------
 5855|      5|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5855:2): [True: 0, False: 957]
  ------------------
 5856|      6|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5856:2): [True: 1, False: 956]
  ------------------
 5857|      6|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  577|      6|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5858|      6|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  583|      6|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5859|      6|				     CI_NO_RANDOM |
  ------------------
  |  |  579|      6|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5860|      6|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  585|      6|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5861|      6|		break;
 5862|       |
 5863|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5863:2): [True: 0, False: 957]
  ------------------
 5864|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  577|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5865|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  585|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5866|      0|		break;
 5867|       |
 5868|     67|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5868:2): [True: 67, False: 890]
  ------------------
 5869|     67|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  577|     67|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5870|     67|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  583|     67|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5871|     67|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  579|     67|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5872|       |							     /* Discovery object returns 6A 82 so is not on card by default */
 5873|     67|		break;
 5874|       |
 5875|      0|	default:
  ------------------
  |  Branch (5875:2): [True: 0, False: 957]
  ------------------
 5876|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  577|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5877|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  585|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5878|       |		/* opensc.conf may have it wrong, continue anyway */
 5879|      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__
  |  |  ------------------
  ------------------
 5880|      0|		card->type = SC_CARD_TYPE_PIV_II_GENERIC;
 5881|    957|	}
 5882|    957|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|    957|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5883|    957|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5884|       |
 5885|    957|	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  582|    957|#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|    951|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (5885:6): [True: 951, False: 6]
  |  Branch (5885:53): [True: 634, False: 317]
  ------------------
 5886|       |		/*
 5887|       |		 * We now know PIV AID is active, test DISCOVERY object again
 5888|       |		 * Some PIV don't support DISCOVERY and return
 5889|       |		 * SC_ERROR_INCORRECT_PARAMETERS. Any error
 5890|       |		 * including SC_ERROR_FILE_NOT_FOUND means we cannot use discovery
 5891|       |		 * to test for active AID.
 5892|       |		 */
 5893|    634|		r2 = piv_find_discovery(card);
 5894|       |
 5895|    634|		if (r2 < 0) {
  ------------------
  |  Branch (5895:7): [True: 549, False: 85]
  ------------------
 5896|    549|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  582|    549|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5897|    549|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  150|    549|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5898|    549|		}
 5899|    634|	}
 5900|       |
 5901|    957|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|    957|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5902|    957|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5903|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 5904|    957|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    957|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    957|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    957|	int _ret = r; \
  |  |  |  |  155|    957|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 957, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    957|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 957]
  |  |  |  |  ------------------
  |  |  |  |  157|    957|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    957|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    957|	return _ret; \
  |  |  |  |  163|    957|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5905|       |
 5906|  4.64k|err:
 5907|  4.64k|	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.64k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5908|  4.64k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5909|       |	/* don't match. Does not have a PIV applet. */
 5910|  4.64k|	piv_finish(card);
 5911|  4.64k|	card->type = saved_type;
 5912|  4.64k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.64k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.64k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.64k|	int _ret = r; \
  |  |  |  |  155|  4.64k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.64k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.64k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.64k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.64k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.64k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.64k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.64k|	return _ret; \
  |  |  |  |  163|  4.64k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5913|  4.64k|}
card-piv.c:piv_find_discovery:
 5062|  4.95k|{
 5063|  4.95k|	int r = 0;
 5064|  4.95k|	size_t rbuflen;
 5065|  4.95k|	u8 *rbuf = NULL;
 5066|  4.95k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  4.95k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5067|       |
 5068|  4.95k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.95k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.95k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.95k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.95k]
  |  |  ------------------
  ------------------
 5069|       |
 5070|       |	/*
 5071|       |	 * During piv_card_reader_lock_obtained,
 5072|       |	 * we use the discovery object to test if card present, and
 5073|       |	 * if PIV AID is active.
 5074|       |	 */
 5075|  4.95k|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  150|  4.95k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5075:6): [True: 0, False: 4.95k]
  ------------------
 5076|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 5077|      0|		goto end;
 5078|      0|	}
 5079|       |
 5080|       |	/* If not valid: read, test,  cache */
 5081|  4.95k|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  148|  4.95k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5081:6): [True: 1.41k, False: 3.54k]
  ------------------
 5082|  1.41k|		r = piv_process_discovery(card);
 5083|  3.54k|	} else {
 5084|       |		/* if already in cache,force read */
 5085|  3.54k|		rbuflen = 1;
 5086|  3.54k|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5087|       |		/* if same response as last, no need to parse */
 5088|  3.54k|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5088:7): [True: 0, False: 3.54k]
  |  Branch (5088:17): [True: 0, False: 0]
  ------------------
 5089|      0|			goto end;
 5090|       |
 5091|  3.54k|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5091:7): [True: 55, False: 3.48k]
  |  Branch (5091:17): [True: 42, False: 13]
  ------------------
 5092|     42|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5092:5): [True: 42, False: 0]
  ------------------
 5093|     42|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5093:5): [True: 20, False: 22]
  ------------------
 5094|     20|			goto end;
 5095|     20|		}
 5096|       |		/* This should not happen  bad card */
 5097|  3.52k|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   71|  3.52k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5098|  3.52k|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  3.52k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5099|  3.52k|		goto end;
 5100|  3.54k|	}
 5101|       |
 5102|  4.95k|end:
 5103|  4.95k|	free(rbuf);
 5104|  4.95k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.95k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.95k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.95k|	int _ret = r; \
  |  |  |  |  155|  4.95k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.93k, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.93k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.53k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.53k, False: 403]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.93k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.93k|	} 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|  4.95k|	return _ret; \
  |  |  |  |  163|  4.95k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5105|  4.95k|}
card-piv.c:piv_process_discovery:
 4955|  1.41k|{
 4956|  1.41k|	int r;
 4957|  1.41k|	u8 *rbuf = NULL;
 4958|  1.41k|	size_t rbuflen = 0;
 4959|       |
 4960|  1.41k|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 4961|       |	/* Note rbuf and rbuflen are now pointers into cache */
 4962|  1.41k|	if (r < 0)
  ------------------
  |  Branch (4962:6): [True: 966, False: 447]
  ------------------
 4963|    966|		goto err;
 4964|       |
 4965|       |	/* the object is now cached, see what we have */
 4966|    447|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 4967|       |
 4968|  1.41k|err:
 4969|  1.41k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.41k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.41k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.41k|	int _ret = r; \
  |  |  |  |  155|  1.41k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.41k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.41k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.01k, False: 403]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4970|  1.41k|}
card-piv.c:piv_get_cached_data:
 3194|  13.9k|{
 3195|       |
 3196|  13.9k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  13.9k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3197|  13.9k|	int r;
 3198|  13.9k|	u8 *rbuf = NULL;
 3199|  13.9k|	size_t rbuflen;
 3200|       |
 3201|  13.9k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  13.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  13.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  13.9k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 13.9k]
  |  |  ------------------
  ------------------
 3202|       |
 3203|  13.9k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3203:6): [True: 0, False: 13.9k]
  |  Branch (3203:21): [True: 0, False: 13.9k]
  ------------------
 3204|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3205|       |
 3206|  13.9k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3207|       |
 3208|       |	/* see if we have it cached */
 3209|  13.9k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  148|  13.9k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3209:6): [True: 2.03k, False: 11.9k]
  ------------------
 3210|       |
 3211|  2.03k|		sc_log(card->ctx,
  ------------------
  |  |   71|  2.03k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3212|  2.03k|				"found #%d %p:%" SC_FORMAT_LEN_SIZE_T "u %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3213|  2.03k|				enumtag,
 3214|  2.03k|				priv->obj_cache[enumtag].obj_data,
 3215|  2.03k|				priv->obj_cache[enumtag].obj_len,
 3216|  2.03k|				priv->obj_cache[enumtag].internal_obj_data,
 3217|  2.03k|				priv->obj_cache[enumtag].internal_obj_len);
 3218|       |
 3219|  2.03k|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3219:7): [True: 0, False: 2.03k]
  ------------------
 3220|      0|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3221|      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__
  |  |  ------------------
  ------------------
 3222|      0|			goto err;
 3223|      0|		}
 3224|  2.03k|		*buf = priv->obj_cache[enumtag].obj_data;
 3225|  2.03k|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3226|  2.03k|		r = (int)*buf_len;
 3227|  2.03k|		goto ok;
 3228|  2.03k|	}
 3229|       |
 3230|       |	/*
 3231|       |	 * If we know it can not be on the card  i.e. History object
 3232|       |	 * has been read, and we know what other certs may or
 3233|       |	 * may not be on the card. We can avoid extra overhead
 3234|       |	 * Also used if object on card was not parsable
 3235|       |	 */
 3236|       |
 3237|  11.9k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  150|  11.9k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3237:6): [True: 0, False: 11.9k]
  ------------------
 3238|      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__
  |  |  ------------------
  ------------------
 3239|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3240|      0|		goto err;
 3241|      0|	}
 3242|       |
 3243|       |	/* Not cached, try to get it, piv_get_data will allocate a buf */
 3244|  11.9k|	sc_log(card->ctx, "get #%d", enumtag);
  ------------------
  |  |   71|  11.9k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3245|  11.9k|	rbuflen = 1;
 3246|  11.9k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3247|  11.9k|	if (r > 0) {
  ------------------
  |  Branch (3247:6): [True: 3.01k, False: 8.93k]
  ------------------
 3248|  3.01k|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|  3.01k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3249|  3.01k|		priv->obj_cache[enumtag].obj_len = r;
 3250|  3.01k|		priv->obj_cache[enumtag].obj_data = rbuf;
 3251|  3.01k|		*buf = rbuf;
 3252|  3.01k|		*buf_len = r;
 3253|       |
 3254|  3.01k|		sc_log(card->ctx,
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
 3255|  3.01k|				"added #%d  %p:%" SC_FORMAT_LEN_SIZE_T "u %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3256|  3.01k|				enumtag,
 3257|  3.01k|				priv->obj_cache[enumtag].obj_data,
 3258|  3.01k|				priv->obj_cache[enumtag].obj_len,
 3259|  3.01k|				priv->obj_cache[enumtag].internal_obj_data,
 3260|  3.01k|				priv->obj_cache[enumtag].internal_obj_len);
 3261|       |
 3262|  8.93k|	} else {
 3263|  8.93k|		free(rbuf);
 3264|  8.93k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  8.93k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3264:7): [True: 0, False: 8.93k]
  |  Branch (3264:17): [True: 1.67k, False: 7.25k]
  ------------------
 3265|  1.67k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.67k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3266|  1.67k|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|  1.67k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3267|  1.67k|			priv->obj_cache[enumtag].obj_len = 0;
 3268|  7.25k|		} else {
 3269|  7.25k|			goto err;
 3270|  7.25k|		}
 3271|  8.93k|	}
 3272|  6.72k|ok:
 3273|       |
 3274|  13.9k|err:
 3275|  13.9k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  13.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  13.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  13.9k|	int _ret = r; \
  |  |  |  |  155|  13.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.93k, False: 5.04k]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.93k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.93k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.93k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.93k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.93k|	} else { \
  |  |  |  |  159|  5.04k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  5.04k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  5.04k|	} \
  |  |  |  |  162|  13.9k|	return _ret; \
  |  |  |  |  163|  13.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3276|  13.9k|}
card-piv.c:piv_parse_discovery:
 4898|    447|{
 4899|    447|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    447|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4900|    447|	int r = 0;
 4901|    447|	const u8 *body;
 4902|    447|	size_t bodylen;
 4903|    447|	const u8 *aid;
 4904|    447|	size_t aidlen;
 4905|    447|	const u8 *pinp;
 4906|    447|	size_t pinplen;
 4907|    447|	unsigned int cla_out, tag_out;
 4908|       |
 4909|    447|	if (rbuflen != 0) {
  ------------------
  |  Branch (4909:6): [True: 447, False: 0]
  ------------------
 4910|    447|		body = rbuf;
 4911|    447|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    894|#define SC_SUCCESS				0
  ------------------
  |  Branch (4911:7): [True: 0, False: 447]
  ------------------
 4912|    447|				body == NULL ||
  ------------------
  |  Branch (4912:5): [True: 0, False: 447]
  ------------------
 4913|    447|				bodylen == 0 ||
  ------------------
  |  Branch (4913:5): [True: 1, False: 446]
  ------------------
 4914|    446|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (4914:5): [True: 0, False: 446]
  ------------------
 4915|      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__
  |  |  ------------------
  ------------------
 4916|      1|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 4917|      1|			goto err;
 4918|      1|		}
 4919|       |
 4920|    446|		sc_log(card->ctx,
  ------------------
  |  |   71|    446|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4921|    446|				"Discovery 0x%2.2x 0x%2.2x %p:%" SC_FORMAT_LEN_SIZE_T "u",
 4922|    446|				cla_out, tag_out, body, bodylen);
 4923|    446|		aidlen = 0;
 4924|    446|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 4925|    446|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (4925:7): [True: 12, False: 434]
  |  Branch (4925:22): [True: 2, False: 432]
  ------------------
 4926|    432|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (4926:5): [True: 29, False: 403]
  ------------------
 4927|     43|			sc_log(card->ctx, "Discovery object not PIV");
  ------------------
  |  |   71|     43|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4928|     43|			r = SC_ERROR_INVALID_CARD; /* This is an error */
  ------------------
  |  |   60|     43|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4929|     43|			goto err;
 4930|     43|		}
 4931|    403|		if (aid_only == 0) {
  ------------------
  |  Branch (4931:7): [True: 403, False: 0]
  ------------------
 4932|    403|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 4933|    403|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (4933:8): [True: 213, False: 190]
  |  Branch (4933:16): [True: 211, False: 2]
  ------------------
 4934|    211|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  380|    211|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 4935|    211|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 4936|    211|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4937|    211|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  368|    211|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  369|    211|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  368|    211|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  369|    211|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (4937:9): [True: 5, False: 206]
  ------------------
 4938|      5|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  374|      5|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (4938:7): [True: 1, False: 4]
  ------------------
 4939|      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__
  |  |  ------------------
  ------------------
 4940|      1|					priv->pin_preference = 0x00;
 4941|      1|				}
 4942|    211|			}
 4943|    403|		}
 4944|    403|		r = SC_SUCCESS;
  ------------------
  |  |   28|    403|#define SC_SUCCESS				0
  ------------------
 4945|    403|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  379|    403|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 4946|    403|	}
 4947|       |
 4948|    447|err:
 4949|    447|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    447|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    447|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    447|	int _ret = r; \
  |  |  |  |  155|    447|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 447, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    447|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     44|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 44, False: 403]
  |  |  |  |  ------------------
  |  |  |  |  157|    447|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    447|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    447|	return _ret; \
  |  |  |  |  163|    447|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4950|    447|}
card-piv.c:piv_get_data:
 3082|  15.5k|{
 3083|  15.5k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  15.5k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3084|  15.5k|	u8 *p;
 3085|  15.5k|	u8 *tbuf;
 3086|  15.5k|	int r = 0;
 3087|  15.5k|	u8 tagbuf[8];
 3088|  15.5k|	size_t tag_len;
 3089|  15.5k|	int alloc_buf = 0;
 3090|       |
 3091|  15.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.5k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.5k]
  |  |  ------------------
  ------------------
 3092|       |
 3093|  15.5k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  15.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3094|       |
 3095|  15.5k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3096|  15.5k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  15.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3096:6): [True: 0, False: 15.5k]
  ------------------
 3097|      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__
  |  |  ------------------
  ------------------
 3098|      0|		return r;
 3099|      0|	}
 3100|       |
 3101|  15.5k|	tag_len = piv_objects[enumtag].tag_len;
 3102|       |
 3103|  15.5k|	p = tagbuf;
 3104|  15.5k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3105|  15.5k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  15.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3105:6): [True: 0, False: 15.5k]
  ------------------
 3106|      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__
  |  |  ------------------
  ------------------
 3107|      0|		goto err;
 3108|      0|	}
 3109|       |
 3110|  15.5k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3110:6): [True: 15.4k, False: 32]
  |  Branch (3110:23): [True: 15.4k, False: 0]
  ------------------
 3111|  15.4k|		*buf_len = priv->max_object_size; /* will allocate below */
 3112|  15.4k|		alloc_buf = 1;
 3113|  15.4k|	}
 3114|       |
 3115|  15.5k|	sc_log(card->ctx,
  ------------------
  |  |   71|  15.5k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3116|  15.5k|			"buffer for #%d *buf=0x%p len=%" SC_FORMAT_LEN_SIZE_T "u",
 3117|  15.5k|			enumtag, *buf, *buf_len);
 3118|  15.5k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3118:6): [True: 15.4k, False: 32]
  |  Branch (3118:22): [True: 15.4k, False: 0]
  ------------------
 3119|  15.4k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  15.4k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3119:7): [True: 0, False: 15.4k]
  ------------------
 3120|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3121|      0|			goto err;
 3122|      0|		}
 3123|  15.4k|		*buf = malloc(*buf_len);
 3124|  15.4k|		if (*buf == NULL) {
  ------------------
  |  Branch (3124:7): [True: 0, False: 15.4k]
  ------------------
 3125|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3126|      0|			goto err;
 3127|      0|		}
 3128|  15.4k|	}
 3129|       |
 3130|       |#ifdef ENABLE_PIV_SM
 3131|       |	/*
 3132|       |	 * Over contact reader, OK to read non sensitive object in clear even when SM is active
 3133|       |	 * but only if using default policy and we are not in reader_lock_obtained
 3134|       |	 * Discovery object will use SM from reader_lock_obtained to catch if SM is still valid
 3135|       |	 * i.e. no interference from other applications
 3136|       |	 */
 3137|       |	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",
 3138|       |			enumtag, card->sm_ctx.sm_mode, piv_objects[enumtag].flags, priv->sm_flags, priv->init_flags);
 3139|       |	if (priv->sm_flags & PIV_SM_FLAGS_SM_IS_ACTIVE &&
 3140|       |			enumtag != PIV_OBJ_DISCOVERY &&
 3141|       |			card->sm_ctx.sm_mode == SM_MODE_TRANSMIT &&
 3142|       |			!(piv_objects[enumtag].flags & PIV_OBJECT_NEEDS_PIN) &&
 3143|       |			!(priv->sm_flags & (PIV_SM_FLAGS_NEVER | PIV_SM_FLAGS_ALWAYS)) &&
 3144|       |			!(priv->init_flags & (PIV_INIT_CONTACTLESS | PIV_INIT_IN_READER_LOCK_OBTAINED))) {
 3145|       |		sc_log(card->ctx, "Set PIV_SM_GET_DATA_IN_CLEAR");
 3146|       |		priv->sm_flags |= PIV_SM_GET_DATA_IN_CLEAR;
 3147|       |	}
 3148|       |
 3149|       |#endif /* ENABLE_PIV_SM */
 3150|  15.5k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3151|  15.5k|	if (r > 0) {
  ------------------
  |  Branch (3151:6): [True: 4.21k, False: 11.3k]
  ------------------
 3152|  4.21k|		int r_tag;
 3153|  4.21k|		unsigned int cla_out, tag_out;
 3154|  4.21k|		size_t bodylen = 0;
 3155|  4.21k|		const u8 *body = *buf;
 3156|  4.21k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3157|  4.21k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  8.42k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3157:7): [True: 686, False: 3.52k]
  |  Branch (3157:30): [True: 80, False: 3.44k]
  ------------------
 3158|  3.44k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3158:5): [True: 377, False: 3.07k]
  ------------------
 3159|  1.14k|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   71|  1.14k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3160|  1.14k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.14k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3161|  1.14k|			goto err;
 3162|  1.14k|		}
 3163|  3.07k|		*buf_len = (body - *buf) + bodylen;
 3164|  11.3k|	} else if (r == 0) {
  ------------------
  |  Branch (3164:13): [True: 524, False: 10.7k]
  ------------------
 3165|    524|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    524|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3166|    524|		goto err;
 3167|  10.7k|	} else {
 3168|  10.7k|		goto err;
 3169|  10.7k|	}
 3170|       |
 3171|  3.07k|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3171:6): [True: 3.06k, False: 1]
  |  Branch (3171:19): [True: 3.06k, False: 0]
  ------------------
 3172|  3.06k|		tbuf = malloc(r);
 3173|  3.06k|		if (tbuf == NULL) {
  ------------------
  |  Branch (3173:7): [True: 0, False: 3.06k]
  ------------------
 3174|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3175|      0|			goto err;
 3176|      0|		}
 3177|  3.06k|		memcpy(tbuf, *buf, r);
 3178|  3.06k|		free(*buf);
 3179|  3.06k|		alloc_buf = 0;
 3180|  3.06k|		*buf = tbuf;
 3181|  3.06k|	}
 3182|       |
 3183|  15.5k|err:
 3184|  15.5k|	if (alloc_buf) {
  ------------------
  |  Branch (3184:6): [True: 12.4k, False: 3.10k]
  ------------------
 3185|  12.4k|		free(*buf);
 3186|  12.4k|		*buf = NULL;
 3187|  12.4k|	}
 3188|  15.5k|	sc_unlock(card);
 3189|  15.5k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  15.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  15.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  15.5k|	int _ret = r; \
  |  |  |  |  155|  15.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.4k, False: 3.07k]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.4k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.4k|	} else { \
  |  |  |  |  159|  3.07k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.07k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.07k|	} \
  |  |  |  |  162|  15.5k|	return _ret; \
  |  |  |  |  163|  15.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3190|  15.5k|}
card-piv.c:piv_general_io:
 1786|  18.4k|{
 1787|  18.4k|	int r;
 1788|  18.4k|	sc_apdu_t apdu;
 1789|       |
 1790|  18.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  18.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  18.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  18.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 18.4k]
  |  |  ------------------
  ------------------
 1791|       |
 1792|  18.4k|	r = sc_lock(card);
 1793|  18.4k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  18.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1793:6): [True: 0, False: 18.4k]
  ------------------
 1794|  18.4k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1795|       |
 1796|  18.4k|	sc_format_apdu(card, &apdu,
 1797|  18.4k|			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  294|  18.4k|#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 (1797:4): [True: 18.4k, False: 0]
  ------------------
 1798|  18.4k|			ins, p1, p2);
 1799|  18.4k|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  18.4k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1800|       |#ifdef ENABLE_PIV_SM
 1801|       |	if (card->sm_ctx.sm_mode != SM_MODE_NONE && sendbuflen > 255) {
 1802|       |		/* tell apdu.c to not do the chaining, let the SM get_apdu do it */
 1803|       |		apdu.flags |= SC_APDU_FLAGS_SM_CHAINING;
 1804|       |	}
 1805|       |#endif
 1806|  18.4k|	apdu.lc = sendbuflen;
 1807|  18.4k|	apdu.datalen = sendbuflen;
 1808|  18.4k|	apdu.data = sendbuf;
 1809|       |
 1810|  18.4k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1810:6): [True: 18.4k, False: 0]
  |  Branch (1810:17): [True: 18.4k, False: 0]
  ------------------
 1811|  18.4k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1811:13): [True: 18.3k, False: 32]
  ------------------
 1812|  18.4k|		apdu.resplen = recvbuflen;
 1813|  18.4k|	} else {
 1814|      0|		apdu.le = 0;
 1815|      0|		apdu.resplen = 0;
 1816|      0|	}
 1817|  18.4k|	apdu.resp = recvbuf;
 1818|       |
 1819|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1820|  18.4k|	r = sc_transmit_apdu(card, &apdu);
 1821|       |
 1822|       |	/* adpu will not have sw1,sw2 set because sc_sm_single_transmit called sc_sm_stop, */
 1823|  18.4k|	if (r < 0) {
  ------------------
  |  Branch (1823:6): [True: 423, False: 17.9k]
  ------------------
 1824|    423|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    423|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1825|    423|		goto err;
 1826|    423|	}
 1827|       |
 1828|  17.9k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1828:6): [True: 112, False: 17.8k]
  |  Branch (1828:26): [True: 39, False: 73]
  ------------------
 1829|     39|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|     39|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1830|  17.9k|	else
 1831|  17.9k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1832|       |
 1833|  17.9k|	if (r < 0) {
  ------------------
  |  Branch (1833:6): [True: 12.8k, False: 5.17k]
  ------------------
 1834|  12.8k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  12.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1835|  12.8k|		goto err;
 1836|  12.8k|	}
 1837|       |
 1838|  5.17k|	r = (int)apdu.resplen;
 1839|       |
 1840|  18.4k|err:
 1841|  18.4k|	sc_unlock(card);
 1842|  18.4k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  18.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.4k|	int _ret = r; \
  |  |  |  |  155|  18.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13.8k, False: 4.53k]
  |  |  |  |  ------------------
  |  |  |  |  156|  13.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  13.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13.2k, False: 631]
  |  |  |  |  ------------------
  |  |  |  |  157|  13.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  13.8k|	} else { \
  |  |  |  |  159|  4.53k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  4.53k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  4.53k|	} \
  |  |  |  |  162|  18.4k|	return _ret; \
  |  |  |  |  163|  18.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1843|  18.4k|}
card-piv.c:piv_obj_cache_free_entry:
 5360|   337k|{
 5361|   337k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|   337k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5362|       |
 5363|   337k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5363:6): [True: 3.01k, False: 334k]
  ------------------
 5364|  3.01k|		free(priv->obj_cache[enumtag].obj_data);
 5365|   337k|	priv->obj_cache[enumtag].obj_data = NULL;
 5366|   337k|	priv->obj_cache[enumtag].obj_len = 0;
 5367|       |
 5368|   337k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5368:6): [True: 2.03k, False: 335k]
  ------------------
 5369|  2.03k|		free(priv->obj_cache[enumtag].internal_obj_data);
 5370|   337k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5371|   337k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5372|   337k|	priv->obj_cache[enumtag].flags = flags;
 5373|       |
 5374|   337k|	return SC_SUCCESS;
  ------------------
  |  |   28|   337k|#define SC_SUCCESS				0
  ------------------
 5375|   337k|}
card-piv.c:piv_find_aid:
 2894|  6.30k|{
 2895|  6.30k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  6.30k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2896|  6.30k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2897|  6.30k|	int r, i, j;
 2898|  6.30k|	const u8 *tag;
 2899|  6.30k|	size_t taglen;
 2900|  6.30k|	const u8 *nextac;
 2901|  6.30k|	const u8 *next80;
 2902|  6.30k|	const u8 *pix;
 2903|  6.30k|	size_t pixlen;
 2904|  6.30k|	const u8 *al_label;
 2905|  6.30k|	size_t al_labellen;
 2906|  6.30k|	const u8 *actag; /* Cipher Suite */
 2907|  6.30k|	size_t actaglen;
 2908|  6.30k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2909|  6.30k|	size_t csailen;
 2910|  6.30k|	size_t resplen = sizeof(rbuf);
 2911|       |#ifdef ENABLE_PIV_SM
 2912|       |	int found_csai = 0;
 2913|       |#endif
 2914|       |
 2915|  6.30k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.30k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.30k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.30k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.30k]
  |  |  ------------------
  ------------------
 2916|       |
 2917|       |	/* first  see if the default application will return a template
 2918|       |	 * that we know about.
 2919|       |	 */
 2920|       |
 2921|  6.30k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2922|  6.30k|	if (r > 0 && priv->aid_der.value && resplen == priv->aid_der.len && !memcmp(priv->aid_der.value, rbuf, resplen)) {
  ------------------
  |  Branch (2922:6): [True: 0, False: 6.30k]
  |  Branch (2922:15): [True: 0, False: 0]
  |  Branch (2922:38): [True: 0, False: 0]
  |  Branch (2922:70): [True: 0, False: 0]
  ------------------
 2923|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2924|       |		/* no need to parse again, same as last time */
 2925|      0|	}
 2926|  6.30k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2926:6): [True: 846, False: 5.45k]
  |  Branch (2926:16): [True: 766, False: 80]
  ------------------
 2927|    766|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2928|    766|		if (tag != NULL) {
  ------------------
  |  Branch (2928:7): [True: 708, False: 58]
  ------------------
 2929|    708|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  377|    708|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
 2930|       |			/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
 2931|       |			/* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
 2932|       |			 * where xx is the SM csID either 27 or 2E.
 2933|       |			 * Some vendors may include entries for supported Algorithms even when
 2934|       |			 * not required. We will use these if possible
 2935|       |			 * Will look for multiple 0x80 with in 0xAC value too.
 2936|       |			 */
 2937|    708|			nextac = tag;
 2938|    747|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2938:11): [True: 39, False: 708]
  ------------------
 2939|    747|						0xAC, &actaglen)) != NULL) {
 2940|     39|				nextac = actag + actaglen;
 2941|       |
 2942|     39|				next80 = actag;
 2943|     92|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2943:12): [True: 53, False: 39]
  ------------------
 2944|     92|							0x80, &csailen)) != NULL) {
 2945|     53|					next80 = csai + csailen;
 2946|     53|					if (csailen == 1) {
  ------------------
  |  Branch (2946:10): [True: 27, False: 26]
  ------------------
 2947|     27|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2948|     27|						j = piv_ai_map_find_by_id(card, *csai);
 2949|     27|						if (j >= 0) {
  ------------------
  |  Branch (2949:11): [True: 16, False: 11]
  ------------------
 2950|     16|							priv->alg_ids |= ai_map[j].ai_flag;
 2951|     16|							continue;
 2952|     16|						}
 2953|       |#ifdef ENABLE_PIV_SM
 2954|       |						/* check if id is NIST SM */
 2955|       |						for (i = 0; i < PIV_CSS_SIZE; i++) {
 2956|       |							if (*csai != css[i].id)
 2957|       |								continue;
 2958|       |							if (found_csai) {
 2959|       |								sc_log(card->ctx, "found multiple csIDs, using first");
 2960|       |							} else {
 2961|       |								priv->cs = &css[i];
 2962|       |								priv->csID = *csai;
 2963|       |								found_csai++;
 2964|       |								priv->init_flags |= PIV_INIT_AID_AC_SM;
 2965|       |							}
 2966|       |						}
 2967|       |#endif /* ENABLE_PIV_SM */
 2968|     27|					}
 2969|     53|				}
 2970|     39|			}
 2971|       |
 2972|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2973|    708|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2974|    708|			if (al_label != NULL) {
  ------------------
  |  Branch (2974:8): [True: 10, False: 698]
  ------------------
 2975|     10|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  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__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2976|     10|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2976:9): [True: 0, False: 10]
  ------------------
 2977|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2978|      0|				}
 2979|     10|				memcpy(priv->al_label, al_label, al_labellen);
 2980|     10|				priv->al_labellen = (int)al_labellen;
 2981|     10|			}
 2982|       |
 2983|    708|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 2984|    708|			if (pix != NULL) {
  ------------------
  |  Branch (2984:8): [True: 676, False: 32]
  ------------------
 2985|    676|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   71|    676|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2986|       |
 2987|       |				/* early cards returned full AID, rather then just the pix */
 2988|    742|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (2988:17): [True: 712, False: 30]
  ------------------
 2989|    712|					if ((pixlen >= piv_aids[i].len_long - 5 &&
  ------------------
  |  Branch (2989:11): [True: 700, False: 12]
  ------------------
 2990|    700|							    memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (2990:12): [True: 394, False: 306]
  ------------------
 2991|    318|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (2991:10): [True: 300, False: 18]
  |  Branch (2991:45): [True: 252, False: 48]
  ------------------
 2992|    646|													     piv_aids[i].len_short) == 0))) {
 2993|    646|						free(priv->aid_der.value); /* free previous value if any */
 2994|    646|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (2994:11): [True: 0, False: 646]
  ------------------
 2995|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2996|      0|						}
 2997|    646|						memcpy(priv->aid_der.value, rbuf, resplen);
 2998|    646|						priv->aid_der.len = resplen;
 2999|    646|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|    646|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    646|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    646|	int _ret = r; \
  |  |  |  |  155|    646|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 640, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  156|    640|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 640]
  |  |  |  |  ------------------
  |  |  |  |  157|    640|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    640|	} else { \
  |  |  |  |  159|      6|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      6|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      6|	} \
  |  |  |  |  162|    646|	return _ret; \
  |  |  |  |  163|    646|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3000|    646|					}
 3001|    712|				}
 3002|    676|			}
 3003|    708|		}
 3004|    766|	}
 3005|       |
 3006|  5.65k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|  5.65k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.65k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.65k|	int _ret = r; \
  |  |  |  |  155|  5.65k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.65k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|  5.65k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.65k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.65k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.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|  5.65k|	return _ret; \
  |  |  |  |  163|  5.65k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3007|  5.65k|}
card-piv.c:piv_ai_map_find_by_id:
 2877|     27|{
 2878|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2879|     27|	int i;
 2880|       |
 2881|    194|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2881:14): [True: 183, False: 11]
  ------------------
 2882|    183|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2882:7): [True: 16, False: 167]
  ------------------
 2883|     16|			return i;
 2884|    183|	}
 2885|     11|	return -1;
 2886|     27|}
card-piv.c:piv_process_ccc:
 5043|    431|{
 5044|    431|	int r = 0;
 5045|    431|	u8 *rbuf = NULL;
 5046|    431|	size_t rbuflen = 0;
 5047|       |
 5048|    431|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    431|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    431|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    431|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 431]
  |  |  ------------------
  ------------------
 5049|    431|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5050|       |
 5051|    431|	if (r < 0)
  ------------------
  |  Branch (5051:6): [True: 371, False: 60]
  ------------------
 5052|    371|		goto err;
 5053|       |
 5054|       |	/* the object is now cached, see what we have */
 5055|     60|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5056|    431|err:
 5057|    431|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    431|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    431|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    431|	int _ret = r; \
  |  |  |  |  155|    431|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 431, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    426|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 426, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|    431|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    431|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    431|	return _ret; \
  |  |  |  |  163|    431|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5058|    431|}
card-piv.c:piv_parse_ccc:
 4979|     60|{
 4980|     60|	int r = 0;
 4981|     60|	const u8 *body;
 4982|     60|	size_t bodylen;
 4983|     60|	unsigned int cla_out, tag_out;
 4984|       |
 4985|     60|	u8 tag;
 4986|     60|	const u8 *end;
 4987|     60|	size_t len;
 4988|       |
 4989|     60|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|     60|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4990|       |
 4991|     60|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     60|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     60|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     60|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 60]
  |  |  ------------------
  ------------------
 4992|       |
 4993|     60|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (4993:6): [True: 0, False: 60]
  |  Branch (4993:22): [True: 0, False: 60]
  ------------------
 4994|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 4995|      0|		goto err;
 4996|      0|	}
 4997|       |
 4998|       |	/* Outer layer is a DER tlv */
 4999|     60|	body = rbuf;
 5000|     60|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    120|#define SC_SUCCESS				0
  ------------------
  |  Branch (5000:6): [True: 0, False: 60]
  ------------------
 5001|     60|			body == NULL ||
  ------------------
  |  Branch (5001:4): [True: 0, False: 60]
  ------------------
 5002|     60|			bodylen == 0 ||
  ------------------
  |  Branch (5002:4): [True: 1, False: 59]
  ------------------
 5003|     59|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (5003:4): [True: 0, False: 59]
  ------------------
 5004|      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__
  |  |  ------------------
  ------------------
 5005|      1|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5006|      1|		goto err;
 5007|      1|	}
 5008|       |
 5009|     59|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  167|     59|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5010|       |
 5011|       |	/* CCC  entries are simple tlv */
 5012|     59|	end = body + bodylen;
 5013|    446|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5013:9): [True: 441, False: 5]
  ------------------
 5014|    441|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len);
 5015|    441|		if (r < 0)
  ------------------
  |  Branch (5015:7): [True: 54, False: 387]
  ------------------
 5016|     54|			goto err;
 5017|    387|		switch (tag) {
  ------------------
  |  Branch (5017:11): [True: 110, False: 277]
  ------------------
 5018|     65|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  173|     65|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5018:3): [True: 65, False: 322]
  ------------------
 5019|     65|			if (len == 0x15) {
  ------------------
  |  Branch (5019:8): [True: 50, False: 15]
  ------------------
 5020|     50|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5020:9): [True: 12, False: 38]
  ------------------
 5021|     12|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  168|     12|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5022|     38|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5022:14): [True: 11, False: 27]
  ------------------
 5023|     11|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  169|     11|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5024|     50|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5024:9): [True: 7, False: 43]
  ------------------
 5025|      7|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  170|      7|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5026|     50|			}
 5027|     65|			break;
 5028|     45|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  174|     45|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5028:3): [True: 45, False: 342]
  ------------------
 5029|     45|			if (len == 0x10) {
  ------------------
  |  Branch (5029:8): [True: 25, False: 20]
  ------------------
 5030|     25|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5030:9): [True: 12, False: 13]
  ------------------
 5031|     12|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  171|     12|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5032|     25|			}
 5033|     45|			break;
 5034|    387|		}
 5035|    387|	}
 5036|       |
 5037|     60|err:
 5038|     60|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     60|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     60|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     60|	int _ret = r; \
  |  |  |  |  155|     60|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 60, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     60|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 55, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|     60|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     60|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     60|	return _ret; \
  |  |  |  |  163|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5039|     60|}
card-piv.c:piv_init:
 5917|    957|{
 5918|    957|	int r = 0;
 5919|    957|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    957|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5920|    957|	unsigned long flags;
 5921|    957|	unsigned long flags_eddsa;
 5922|    957|	unsigned long flags_xeddsa;
 5923|    957|	unsigned long ext_flags;
 5924|       |
 5925|    957|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    957|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    957|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    957|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 957]
  |  |  ------------------
  ------------------
 5926|       |
 5927|    957|	r = sc_lock(card); /* hold until match or init is complete */
 5928|    957|	LOG_TEST_RET(card->ctx, r, "sc_lock failed");
  ------------------
  |  |  174|    957|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    957|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    957|	int _ret = (r); \
  |  |  |  |  168|    957|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 957]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    957|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 957]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5929|       |
 5930|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 5931|    957|	if (priv == NULL) {
  ------------------
  |  Branch (5931:6): [True: 0, False: 957]
  ------------------
 5932|      0|		r = piv_match_card_continued(card);
 5933|      0|		priv = PIV_DATA(card);
  ------------------
  |  |  432|      0|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5934|      0|		if (r < 0 || !priv) {
  ------------------
  |  Branch (5934:7): [True: 0, False: 0]
  |  Branch (5934:16): [True: 0, False: 0]
  ------------------
 5935|      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__
  |  |  ------------------
  ------------------
 5936|      0|			sc_unlock(card);
 5937|      0|			piv_finish(card);
 5938|       |			/* tell sc_connect_card to try other driver */
 5939|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5940|      0|		}
 5941|      0|	}
 5942|       |
 5943|       |	/* read "card_driver PIV-II" opensc.conf options, and env parameters */
 5944|    957|	piv_load_options(card);
 5945|       |
 5946|    957|	priv->pstate = PIV_STATE_INIT;
 5947|       |
 5948|    957|	sc_log(card->ctx,
  ------------------
  |  |   71|    957|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5949|    957|			"Max send = %" SC_FORMAT_LEN_SIZE_T "u recv = %" SC_FORMAT_LEN_SIZE_T "u card->type:%d, CI:%08x AI:%08x",
 5950|    957|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 5951|    957|	card->cla = 0x00;
 5952|    957|	if (card->name == NULL)
  ------------------
  |  Branch (5952:6): [True: 957, False: 0]
  ------------------
 5953|    957|		card->name = card->driver->name;
 5954|       |
 5955|    957|	priv->enumtag = piv_aids[0].enumtag;
 5956|       |
 5957|       |	/* PKCS#11 may try to generate session keys, and get confused
 5958|       |	 * if SC_ALGORITHM_ONBOARD_KEY_GEN is present
 5959|       |	 * piv-tool can still do this, just don't tell PKCS#11
 5960|       |	 */
 5961|       |
 5962|    957|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  111|    957|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 5963|       |
 5964|    957|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (5964:6): [True: 0, False: 957]
  ------------------
 5965|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 5966|      0|	}
 5967|       |
 5968|    957|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  592|    957|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (5968:6): [True: 956, False: 1]
  ------------------
 5969|    956|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 5970|       |
 5971|    957|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  593|    957|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (5971:6): [True: 955, False: 2]
  ------------------
 5972|    955|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 5973|       |
 5974|    957|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  594|    957|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (5974:6): [True: 956, False: 1]
  ------------------
 5975|    956|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 5976|       |
 5977|    957|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  595|    957|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (5977:6): [True: 115, False: 842]
  ------------------
 5978|    115|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 5979|       |
 5980|    957|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  589|    957|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (5980:6): [True: 957, False: 0]
  ------------------
 5981|    957|		int i;
 5982|    957|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  183|    957|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  182|    957|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|    957|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    957|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 5983|    957|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|    957|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|    957|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 5984|    957|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  197|    957|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 5985|    957|		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  198|    957|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
              		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  182|    957|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 5986|       |
 5987|  4.78k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (5987:15): [True: 3.82k, False: 957]
  ------------------
 5988|  3.82k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   79|  3.82k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (5988:8): [True: 1.91k, False: 1.91k]
  ------------------
 5989|  1.91k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  588|  3.82k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (5989:11): [True: 574, False: 1.34k]
  |  Branch (5989:46): [True: 287, False: 287]
  ------------------
 5990|  1.62k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 5991|  1.91k|			}
 5992|       |
 5993|  1.91k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  598|  3.82k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   81|    220|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (5993:13): [True: 220, False: 1.69k]
  |  Branch (5993:41): [True: 110, False: 110]
  ------------------
 5994|    110|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 5995|       |
 5996|  1.80k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  599|  3.60k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|    111|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (5996:13): [True: 111, False: 1.69k]
  |  Branch (5996:42): [True: 110, False: 1]
  ------------------
 5997|    110|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 5998|  3.82k|		}
 5999|    957|	}
 6000|       |
 6001|    957|	if (!(priv->card_issues & CI_NO_RANDOM))
  ------------------
  |  |  579|    957|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (6001:6): [True: 884, False: 73]
  ------------------
 6002|    884|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    884|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 6003|       |
 6004|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6005|    957|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    957|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 6006|       |
 6007|       |	/*
 6008|       |	 * 800-73-3 cards may have discovery. "piv-like cards may or may not.
 6009|       |	 * 800-73-4 with VCI must have it as it has the pin policy needed for VCI .
 6010|       |	 */
 6011|       |
 6012|       |#ifdef ENABLE_PIV_SM
 6013|       |	/*
 6014|       |	 * 800-73-4
 6015|       |	 * Response of AID says if SM is supported. Look for Cipher Suite
 6016|       |	 */
 6017|       |	if (priv->csID && priv->cs != NULL) {
 6018|       |		/*
 6019|       |		 * Main point in SM and VCI is to allow contactless access
 6020|       |		 */
 6021|       |		/* Only piv_init and piv_reader_lock_obtained should call piv_sm_open */
 6022|       |
 6023|       |		/* If user said PIV_SM_FLAGS_NEVER, dont start SM; implies limited contatless access */
 6024|       |		if (priv->sm_flags & PIV_SM_FLAGS_NEVER) {
 6025|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_NEVER");
 6026|       |			r = SC_SUCCESS; /* Users choice */
 6027|       |
 6028|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6029|       |				!(priv->pin_policy & PIV_PP_VCI_IMPL)) {
 6030|       |			sc_log(card->ctx, "Contactless and no card support for VCI");
 6031|       |			r = SC_SUCCESS; /* User should know VCI is not possible with their card; use like 800-73-3 contactless  */
 6032|       |
 6033|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6034|       |				!(priv->pin_policy & PIV_PP_VCI_WITHOUT_PC) &&
 6035|       |				(priv->pairing_code[0] == 0x00)) {
 6036|       |			sc_log(card->ctx, "Contactless, pairing_code required and no pairing code");
 6037|       |			r = SC_ERROR_PIN_CODE_INCORRECT; /* User should know they need to set pairing code */
 6038|       |
 6039|       |		} else {
 6040|       |			priv->sm_flags |= PIV_SM_FLAGS_DEFER_OPEN; /* tell priv_sm_open, OK to open */
 6041|       |			r = piv_sm_open(card);
 6042|       |			sc_log(card->ctx, "piv_sm_open returned:%d", r);
 6043|       |		}
 6044|       |
 6045|       |		/* If failed, and user said PIV_SM_FLAGS_ALWAYS quit */
 6046|       |		if (priv->sm_flags & PIV_SM_FLAGS_ALWAYS && r < 0) {
 6047|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_ALWAYS, SM has failed to start, don't use the card");
 6048|       |			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ALLOWED);
 6049|       |		}
 6050|       |
 6051|       |		/* user has wrong or no required pairing code */
 6052|       |		if (r == SC_ERROR_PIN_CODE_INCORRECT)
 6053|       |			LOG_FUNC_RETURN(card->ctx, r);
 6054|       |
 6055|       |		/* If SM did not start, or is not expected to start, continue on without it */
 6056|       |	}
 6057|       |#endif /* ENABLE_PIV_SM */
 6058|       |
 6059|       |	/*
 6060|       |	 * 800-73-3 cards may have a history object
 6061|       |	 * We want to process it now as this has information on what
 6062|       |	 * keys and certs. "piv like" cards may or may not have history
 6063|       |	 */
 6064|    957|	piv_process_history(card);
 6065|       |
 6066|    957|	priv->pstate = PIV_STATE_NORMAL;
 6067|    957|	sc_unlock(card);
 6068|    957|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    957|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    957|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    957|	int _ret = r; \
  |  |  |  |  155|    957|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 957, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    957|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 957]
  |  |  |  |  ------------------
  |  |  |  |  157|    957|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    957|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    957|	return _ret; \
  |  |  |  |  163|    957|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6069|    957|}
card-piv.c:piv_load_options:
 1678|    957|{
 1679|    957|	int r;
 1680|    957|	size_t i, j;
 1681|    957|	scconf_block **found_blocks, *block;
 1682|       |
 1683|       |#ifdef ENABLE_PIV_SM
 1684|       |	piv_private_data_t *priv = PIV_DATA(card);
 1685|       |	const char *option = NULL;
 1686|       |	int piv_pairing_code_found = 0;
 1687|       |	int piv_use_sm_found = 0;
 1688|       |
 1689|       |	/* pairing code is 8 decimal digits and is card specific */
 1690|       |	if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
 1691|       |		sc_log(card->ctx, "getenv(\"PIV_PAIRING_CODE\") found");
 1692|       |		if (piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1693|       |			memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1694|       |			piv_pairing_code_found = 1;
 1695|       |		}
 1696|       |	}
 1697|       |
 1698|       |	if ((option = getenv("PIV_USE_SM")) != NULL) {
 1699|       |		sc_log(card->ctx, "getenv(\"PIV_USE_SM\")=\"%s\"", option);
 1700|       |		if (!strcmp(option, "never")) {
 1701|       |			priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1702|       |			piv_use_sm_found = 1;
 1703|       |		} else if (!strcmp(option, "always")) {
 1704|       |			priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1705|       |			piv_use_sm_found = 1;
 1706|       |		} else {
 1707|       |			sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1708|       |		}
 1709|       |	}
 1710|       |#endif
 1711|       |
 1712|  1.91k|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (1712:14): [True: 957, False: 957]
  ------------------
 1713|    957|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
 1714|    957|				"card_driver", "PIV-II");
 1715|    957|		if (!found_blocks)
  ------------------
  |  Branch (1715:7): [True: 0, False: 957]
  ------------------
 1716|      0|			continue;
 1717|       |
 1718|    957|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (1718:40): [True: 0, False: 957]
  ------------------
 1719|       |
 1720|       |#ifdef ENABLE_PIV_SM
 1721|       |			/*
 1722|       |			 * "piv_use_sm" if card supports NIST sp800-73-4 sm, when should it be used
 1723|       |			 * never - use card like 800-73-3, i.e. contactless is very limited on
 1724|       |			 * true PIV cards. Some  PIV-like" card may allow this.
 1725|       |			 * this security risk
 1726|       |			 * always - Use even for contact interface.
 1727|       |			 * PINS, crypto and reading of object will not show up in logs
 1728|       |			 * or over network.
 1729|       |			 */
 1730|       |
 1731|       |			if (piv_use_sm_found == 0) {
 1732|       |				option = scconf_get_str(block, "piv_use_sm", "default");
 1733|       |				sc_log(card->ctx, "conf: \"piv_use_sm\"=\"%s\"", option);
 1734|       |				if (!strcmp(option, "default")) {
 1735|       |					/* no new flags */
 1736|       |				} else if (!strcmp(option, "never")) {
 1737|       |					priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1738|       |				} else if (!strcmp(option, "always")) {
 1739|       |					priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1740|       |				} else {
 1741|       |					sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1742|       |				}
 1743|       |			}
 1744|       |
 1745|       |			/* This is really a card specific value and should not be in the conf file */
 1746|       |			if (piv_pairing_code_found == 0) {
 1747|       |				option = scconf_get_str(block, "piv_pairing_code", NULL);
 1748|       |				if (option && piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1749|       |					memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1750|       |				}
 1751|       |			}
 1752|       |#endif
 1753|      0|		}
 1754|    957|		free(found_blocks);
 1755|    957|	}
 1756|    957|	r = SC_SUCCESS;
  ------------------
  |  |   28|    957|#define SC_SUCCESS				0
  ------------------
 1757|    957|	return r;
 1758|    957|}
card-piv.c:piv_process_history:
 5115|    957|{
 5116|    957|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    957|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5117|    957|	int r;
 5118|    957|	int i, tmplen, tmplen2, tmplen3;
 5119|    957|	int enumtag;
 5120|    957|	u8 *rbuf = NULL;
 5121|    957|	size_t rbuflen = 0;
 5122|    957|	const u8 *body;
 5123|    957|	size_t bodylen;
 5124|    957|	const u8 *num;
 5125|    957|	size_t numlen;
 5126|    957|	const u8 *url = NULL;
 5127|    957|	size_t urllen;
 5128|    957|	u8 *ocfhfbuf = NULL;
 5129|    957|	unsigned int cla_out, tag_out;
 5130|    957|	size_t ocfhflen;
 5131|    957|	const u8 *seq;
 5132|    957|	const u8 *seqtag;
 5133|    957|	size_t seqlen;
 5134|    957|	const u8 *keyref;
 5135|    957|	size_t keyreflen;
 5136|    957|	const u8 *cert;
 5137|    957|	size_t certlen;
 5138|    957|	size_t certobjlen, i2;
 5139|    957|	u8 *certobj;
 5140|    957|	u8 *cp;
 5141|       |
 5142|    957|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    957|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    957|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    957|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 957]
  |  |  ------------------
  ------------------
 5143|       |
 5144|    957|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5145|    957|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    957|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5145:6): [True: 128, False: 829]
  ------------------
 5146|    128|		r = 0; /* OK if not found */
 5147|    957|	if (r <= 0) {
  ------------------
  |  Branch (5147:6): [True: 678, False: 279]
  ------------------
 5148|    678|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|    678|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5149|    678|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5150|    678|	}
 5151|       |
 5152|       |	/* the object is now cached, see what we have */
 5153|    279|	if (rbuflen != 0) {
  ------------------
  |  Branch (5153:6): [True: 279, False: 0]
  ------------------
 5154|    279|		body = rbuf;
 5155|    279|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    558|#define SC_SUCCESS				0
  ------------------
  |  Branch (5155:7): [True: 0, False: 279]
  ------------------
 5156|    279|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5156:5): [True: 0, False: 279]
  ------------------
 5157|      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__
  |  |  ------------------
  ------------------
 5158|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5159|      0|			goto err;
 5160|      0|		}
 5161|       |
 5162|    279|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5162:7): [True: 279, False: 0]
  |  Branch (5162:23): [True: 268, False: 11]
  ------------------
 5163|    268|			numlen = 0;
 5164|    268|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5165|    268|			if (num) {
  ------------------
  |  Branch (5165:8): [True: 238, False: 30]
  ------------------
 5166|    238|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5166:9): [True: 1, False: 237]
  |  Branch (5166:24): [True: 2, False: 235]
  ------------------
 5167|      3|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5168|      3|					goto err;
 5169|      3|				}
 5170|       |
 5171|    235|				priv->keysWithOnCardCerts = *num;
 5172|    235|			}
 5173|       |
 5174|    265|			numlen = 0;
 5175|    265|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5176|    265|			if (num) {
  ------------------
  |  Branch (5176:8): [True: 223, False: 42]
  ------------------
 5177|    223|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5177:9): [True: 1, False: 222]
  |  Branch (5177:24): [True: 1, False: 221]
  ------------------
 5178|      2|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5179|      2|					goto err;
 5180|      2|				}
 5181|       |
 5182|    221|				priv->keysWithOffCardCerts = *num;
 5183|    221|			}
 5184|       |
 5185|    263|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5186|    263|			if (url) {
  ------------------
  |  Branch (5186:8): [True: 222, False: 41]
  ------------------
 5187|    222|				if (urllen > 118) {
  ------------------
  |  Branch (5187:9): [True: 0, False: 222]
  ------------------
 5188|      0|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5189|      0|					goto err;
 5190|      0|				}
 5191|    222|				priv->offCardCertURL = calloc(1, urllen + 1);
 5192|    222|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5192:9): [True: 0, False: 222]
  ------------------
 5193|    222|					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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5194|    222|				memcpy(priv->offCardCertURL, url, urllen);
 5195|    222|			}
 5196|    263|		} else {
 5197|     11|			sc_log(card->ctx, "Problem with History object\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__
  |  |  ------------------
  ------------------
 5198|     11|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
 5199|     11|			goto err;
 5200|     11|		}
 5201|    279|	}
 5202|    263|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 222, False: 41]
  |  |  ------------------
  ------------------
 5203|    263|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5204|    263|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5205|       |
 5206|       |	/* now mark what objects are on the card */
 5207|  3.66k|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5207:14): [True: 3.40k, False: 263]
  ------------------
 5208|  3.40k|		priv->obj_cache[PIV_OBJ_RETIRED_X509_1 + i].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|  3.66k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5209|       |
 5210|       |	/*
 5211|       |	 * If user has gotten copy of the file from the offCardCertsURL,
 5212|       |	 * we will read in and add the certs to the cache as listed on
 5213|       |	 * the card. some of the certs may be on the card as well.
 5214|       |	 *
 5215|       |	 * Get file name from url. verify that the filename is valid
 5216|       |	 * The URL ends in a SHA-256 string. We will use this as the filename
 5217|       |	 * in the directory used for the  PKCS15 cache
 5218|       |	 * "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
 5219|       |	 */
 5220|       |
 5221|    263|	r = 0;
 5222|    263|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5222:6): [True: 222, False: 41]
  ------------------
 5223|    222|		char *fp;
 5224|    222|		char filename[PATH_MAX];
 5225|       |
 5226|    222|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5226:7): [True: 200, False: 22]
  ------------------
 5227|    200|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    200|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5228|    200|			goto err;
 5229|    200|		}
 5230|       |		/* find the last /  so we have the filename part */
 5231|     22|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5232|     22|		if (fp == NULL) {
  ------------------
  |  Branch (5232:7): [True: 4, False: 18]
  ------------------
 5233|      4|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      4|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5234|      4|			goto err;
 5235|      4|		}
 5236|     18|		fp++;
 5237|     18|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5237:7): [True: 11, False: 7]
  ------------------
 5238|     11|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     11|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5239|     11|			goto err;
 5240|     11|		}
 5241|    113|		for (i = 0; i < 64; i++) {
  ------------------
  |  Branch (5241:15): [True: 112, False: 1]
  ------------------
 5242|    112|			if (isxdigit((unsigned char)fp[i]) == 0) {
  ------------------
  |  Branch (5242:8): [True: 6, False: 106]
  ------------------
 5243|      6|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      6|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5244|      6|				goto err;
 5245|      6|			}
 5246|    112|		}
 5247|       |
 5248|       |		/* Use the same directory as used for other OpenSC cached items */
 5249|      1|		r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);
 5250|      1|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (5250:7): [True: 0, False: 1]
  ------------------
 5251|      0|			goto err;
 5252|       |#ifdef _WIN32
 5253|       |		strlcat(filename, "\\", PATH_MAX);
 5254|       |#else
 5255|      1|		strlcat(filename, "/", PATH_MAX);
 5256|      1|#endif
 5257|      1|		strlcat(filename, fp, PATH_MAX);
 5258|       |
 5259|      1|		r = piv_read_obj_from_file(card, filename,
 5260|      1|				&ocfhfbuf, &ocfhflen);
 5261|      1|		if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5261:7): [True: 1, False: 0]
  ------------------
 5262|      1|			r = 0;
 5263|      1|			goto err;
 5264|      1|		}
 5265|       |
 5266|       |		/*
 5267|       |		 * Its a seq of seq of a key ref and cert
 5268|       |		 */
 5269|       |
 5270|      0|		body = ocfhfbuf;
 5271|      0|		if (sc_asn1_read_tag(&body, ocfhflen, &cla_out, &tag_out, &bodylen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5271:7): [True: 0, False: 0]
  ------------------
 5272|      0|				body == NULL ||
  ------------------
  |  Branch (5272:5): [True: 0, False: 0]
  ------------------
 5273|      0|				bodylen == 0 ||
  ------------------
  |  Branch (5273:5): [True: 0, False: 0]
  ------------------
 5274|      0|				(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5274:5): [True: 0, False: 0]
  ------------------
 5275|      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__
  |  |  ------------------
  ------------------
 5276|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5277|      0|			goto err;
 5278|      0|		}
 5279|      0|		seq = body;
 5280|      0|		while (bodylen > 0) {
  ------------------
  |  Branch (5280:10): [True: 0, False: 0]
  ------------------
 5281|      0|			seqtag = seq;
 5282|      0|			if (sc_asn1_read_tag(&seq, bodylen, &cla_out, &tag_out, &seqlen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5282:8): [True: 0, False: 0]
  ------------------
 5283|      0|					seq == 0 ||
  ------------------
  |  Branch (5283:6): [True: 0, False: 0]
  ------------------
 5284|      0|					seqlen == 0 ||
  ------------------
  |  Branch (5284:6): [True: 0, False: 0]
  ------------------
 5285|      0|					(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5285:6): [True: 0, False: 0]
  ------------------
 5286|      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__
  |  |  ------------------
  ------------------
 5287|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5288|      0|				goto err;
 5289|      0|			}
 5290|      0|			keyref = sc_asn1_find_tag(card->ctx, seq, seqlen, 0x04, &keyreflen);
 5291|      0|			if (!keyref || keyreflen != 1 ||
  ------------------
  |  Branch (5291:8): [True: 0, False: 0]
  |  Branch (5291:19): [True: 0, False: 0]
  ------------------
 5292|      0|					(*keyref < 0x82 || *keyref > 0x95)) {
  ------------------
  |  Branch (5292:7): [True: 0, False: 0]
  |  Branch (5292:25): [True: 0, False: 0]
  ------------------
 5293|      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__
  |  |  ------------------
  ------------------
 5294|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5295|      0|				goto err;
 5296|      0|			}
 5297|      0|			cert = keyref + keyreflen;
 5298|      0|			certlen = seqlen - (cert - seq);
 5299|       |
 5300|      0|			enumtag = PIV_OBJ_RETIRED_X509_1 + *keyref - 0x82;
 5301|       |			/* now add the cert like another object */
 5302|       |
 5303|      0|			if ((tmplen = sc_asn1_put_tag(0x70, NULL, certlen, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5303:8): [True: 0, False: 0]
  ------------------
 5304|      0|					(tmplen2 = sc_asn1_put_tag(0x71, NULL, 1, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5304:6): [True: 0, False: 0]
  ------------------
 5305|      0|					(tmplen3 = sc_asn1_put_tag(0xFE, NULL, 0, NULL, 0, NULL)) <= 0) {
  ------------------
  |  Branch (5305:6): [True: 0, False: 0]
  ------------------
 5306|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5307|      0|				goto err;
 5308|      0|			}
 5309|      0|			i2 = tmplen + tmplen2 + tmplen3;
 5310|      0|			tmplen = sc_asn1_put_tag(0x53, NULL, i2, NULL, 0, NULL);
 5311|      0|			if (tmplen <= 0) {
  ------------------
  |  Branch (5311:8): [True: 0, False: 0]
  ------------------
 5312|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5313|      0|				goto err;
 5314|      0|			}
 5315|       |
 5316|      0|			certobjlen = tmplen;
 5317|      0|			certobj = malloc(certobjlen);
 5318|      0|			if (certobj == NULL) {
  ------------------
  |  Branch (5318:8): [True: 0, False: 0]
  ------------------
 5319|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 5320|      0|				goto err;
 5321|      0|			}
 5322|      0|			cp = certobj;
 5323|      0|			if ((r = sc_asn1_put_tag(0x53, NULL, i2, cp, certobjlen, &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5323:8): [True: 0, False: 0]
  ------------------
 5324|      0|					(r = sc_asn1_put_tag(0x70, cert, certlen, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5324:6): [True: 0, False: 0]
  ------------------
 5325|      0|					(r = sc_asn1_put_tag(0x71, NULL, 1, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5325:6): [True: 0, False: 0]
  ------------------
 5326|      0|				goto err;
 5327|      0|			}
 5328|      0|			*cp++ = 0x00;
 5329|      0|			r = sc_asn1_put_tag(0xFE, NULL, 0, cp, certobjlen - (cp - certobj), &cp);
 5330|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5330:8): [True: 0, False: 0]
  ------------------
 5331|      0|				goto err;
 5332|      0|			}
 5333|       |
 5334|      0|			priv->obj_cache[enumtag].obj_data = certobj;
 5335|      0|			priv->obj_cache[enumtag].obj_len = certobjlen;
 5336|      0|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|      0|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 5337|      0|			priv->obj_cache[enumtag].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5338|       |
 5339|      0|			r = piv_cache_internal_data(card, enumtag);
 5340|      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__
  |  |  ------------------
  ------------------
 5341|       |
 5342|      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__
  |  |  ------------------
  ------------------
 5343|      0|					"Added from off card file #%d %p:%" SC_FORMAT_LEN_SIZE_T "u 0x%02X",
 5344|      0|					enumtag,
 5345|      0|					priv->obj_cache[enumtag].obj_data,
 5346|      0|					priv->obj_cache[enumtag].obj_len, *keyref);
 5347|       |
 5348|      0|			bodylen -= (seqlen + seq - seqtag);
 5349|      0|			seq += seqlen;
 5350|      0|		}
 5351|      0|	}
 5352|    957|err:
 5353|    957|	if (ocfhfbuf)
  ------------------
  |  Branch (5353:6): [True: 0, False: 957]
  ------------------
 5354|      0|		free(ocfhfbuf);
 5355|    957|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    957|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    957|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    957|	int _ret = r; \
  |  |  |  |  155|    957|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 957, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    957|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    776|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 776, False: 181]
  |  |  |  |  ------------------
  |  |  |  |  157|    957|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    957|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    957|	return _ret; \
  |  |  |  |  163|    957|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5356|    957|}
card-piv.c:piv_read_obj_from_file:
 3018|      1|{
 3019|      1|	int r;
 3020|      1|	int r_tag;
 3021|      1|	int f = -1;
 3022|      1|	size_t len;
 3023|      1|	u8 tagbuf[16];
 3024|      1|	size_t rbuflen;
 3025|      1|	const u8 *body;
 3026|      1|	unsigned int cla_out, tag_out;
 3027|      1|	size_t bodylen;
 3028|       |
 3029|      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]
  |  |  ------------------
  ------------------
 3030|       |
 3031|      1|	*buf = NULL;
 3032|      1|	*buf_len = 0;
 3033|      1|	f = open(filename, O_RDONLY);
 3034|      1|	if (f < 0) {
  ------------------
  |  Branch (3034:6): [True: 1, False: 0]
  ------------------
 3035|      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__
  |  |  ------------------
  ------------------
 3036|      1|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3037|      1|		goto err;
 3038|      1|	}
 3039|      0|	len = read(f, tagbuf, sizeof(tagbuf)); /* get tag and length */
 3040|      0|	if (len < 2 || len > sizeof(tagbuf)) {
  ------------------
  |  Branch (3040:6): [True: 0, False: 0]
  |  Branch (3040:17): [True: 0, False: 0]
  ------------------
 3041|      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__
  |  |  ------------------
  ------------------
 3042|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 3043|      0|		goto err;
 3044|      0|	}
 3045|      0|	body = tagbuf;
 3046|       |	/* accept any tag for now, just get length */
 3047|      0|	r_tag = sc_asn1_read_tag(&body, len, &cla_out, &tag_out, &bodylen);
 3048|      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 (3048:7): [True: 0, False: 0]
  |  Branch (3048:30): [True: 0, False: 0]
  ------------------
 3049|      0|			body == NULL) {
  ------------------
  |  Branch (3049:4): [True: 0, False: 0]
  ------------------
 3050|      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__
  |  |  ------------------
  ------------------
 3051|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3052|      0|		goto err;
 3053|      0|	}
 3054|      0|	rbuflen = body - tagbuf + bodylen;
 3055|      0|	*buf = malloc(rbuflen);
 3056|      0|	if (!*buf) {
  ------------------
  |  Branch (3056:6): [True: 0, False: 0]
  ------------------
 3057|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3058|      0|		goto err;
 3059|      0|	}
 3060|      0|	memcpy(*buf, tagbuf, MIN(len, rbuflen)); /* copy first or only part */
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 3061|       |	/* read rest of file */
 3062|      0|	if (rbuflen > len + sizeof(tagbuf)) {
  ------------------
  |  Branch (3062:6): [True: 0, False: 0]
  ------------------
 3063|      0|		len = read(f, *buf + sizeof(tagbuf), rbuflen - sizeof(tagbuf)); /* read rest */
 3064|      0|		if (len != rbuflen - sizeof(tagbuf)) {
  ------------------
  |  Branch (3064:7): [True: 0, False: 0]
  ------------------
 3065|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 3066|      0|			free(*buf);
 3067|      0|			*buf = NULL;
 3068|      0|			goto err;
 3069|      0|		}
 3070|      0|	}
 3071|      0|	r = (int)rbuflen;
 3072|      0|	*buf_len = rbuflen;
 3073|      1|err:
 3074|      1|	if (f >= 0)
  ------------------
  |  Branch (3074:6): [True: 0, False: 1]
  ------------------
 3075|      0|		close(f);
 3076|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3077|      1|}
card-piv.c:piv_cache_internal_data:
 3280|  4.18k|{
 3281|  4.18k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  4.18k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3282|  4.18k|	const u8 *tag;
 3283|  4.18k|	const u8 *body;
 3284|  4.18k|	size_t taglen;
 3285|  4.18k|	size_t bodylen;
 3286|  4.18k|	int compressed = 0;
 3287|  4.18k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  4.18k|#define SC_SUCCESS				0
  ------------------
 3288|       |#ifdef ENABLE_PIV_SM
 3289|       |	u8 *cvc_start = NULL;
 3290|       |	size_t cvc_len = 0;
 3291|       |#endif
 3292|       |
 3293|       |	/* if already cached */
 3294|  4.18k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3294:6): [True: 2.03k, False: 2.14k]
  |  Branch (3294:52): [True: 2.03k, False: 0]
  ------------------
 3295|  2.03k|		sc_log(card->ctx,
  ------------------
  |  |   71|  2.03k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3296|  2.03k|				"#%d found internal %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3297|  2.03k|				enumtag,
 3298|  2.03k|				priv->obj_cache[enumtag].internal_obj_data,
 3299|  2.03k|				priv->obj_cache[enumtag].internal_obj_len);
 3300|  2.03k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.03k|	int _ret = r; \
  |  |  |  |  155|  2.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.03k|	return _ret; \
  |  |  |  |  163|  2.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3301|  2.03k|	}
 3302|       |
 3303|  2.14k|	body = sc_asn1_find_tag(card->ctx,
 3304|  2.14k|			priv->obj_cache[enumtag].obj_data,
 3305|  2.14k|			priv->obj_cache[enumtag].obj_len,
 3306|  2.14k|			0x53, &bodylen);
 3307|       |
 3308|  2.14k|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3308:6): [True: 0, False: 2.14k]
  |  Branch (3308:22): [True: 0, False: 2.14k]
  ------------------
 3309|  2.14k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3310|       |
 3311|       |	/* get the certificate out */
 3312|  2.14k|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  636|  2.14k|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3312:6): [True: 2.14k, False: 0]
  ------------------
 3313|       |
 3314|  2.14k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x71, &taglen);
 3315|       |		/* 800-72-1 not clear if this is 80 or 01 Sent comment to NIST for 800-72-2 */
 3316|       |		/* 800-73-3 says it is 01, keep dual test so old cards still work */
 3317|  2.14k|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3317:7): [True: 1.21k, False: 937]
  |  Branch (3317:14): [True: 1.17k, False: 31]
  |  Branch (3317:29): [True: 10, False: 1.16k]
  |  Branch (3317:48): [True: 11, False: 1.15k]
  ------------------
 3318|     21|			compressed = 1;
 3319|       |
 3320|       |#ifdef ENABLE_PIV_SM
 3321|       |		cvc_start = (u8 *)tag + taglen; /* save for later as cvs (if present) follows  0x71 */
 3322|       |#endif
 3323|       |
 3324|  2.14k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3325|  2.14k|		if (tag == NULL)
  ------------------
  |  Branch (3325:7): [True: 102, False: 2.04k]
  ------------------
 3326|  2.14k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|    102|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    102|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    102|	int _ret = r; \
  |  |  |  |  155|    102|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 102, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    102|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    102|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 102, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    102|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    102|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    102|	return _ret; \
  |  |  |  |  163|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3327|       |
 3328|  2.04k|		if (taglen == 0)
  ------------------
  |  Branch (3328:7): [True: 10, False: 2.03k]
  ------------------
 3329|  2.04k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3330|       |
 3331|  2.03k|		if (compressed) {
  ------------------
  |  Branch (3331:7): [True: 21, False: 2.01k]
  ------------------
 3332|     21|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  149|     21|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3333|     21|		}
 3334|       |		/* internal certificate remains compressed */
 3335|  2.03k|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3335:7): [True: 0, False: 2.03k]
  ------------------
 3336|  2.03k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3337|       |
 3338|  2.03k|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3339|  2.03k|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3340|       |
 3341|       |#ifdef ENABLE_PIV_SM
 3342|       |		/* PIV_OBJ_SM_CERT_SIGNER  CERT OBJECT may also have a intermediate CVC */
 3343|       |		if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CVC) {
 3344|       |			/* cvc if present should be at cvc_start.
 3345|       |			 * find the tag(T) and get value(V) and len(L) from TLV.
 3346|       |			 * Could reconstruct ASN1 of (T)(L) stating location from length and known tag.
 3347|       |			 * as the size of (L) depends on the length of value
 3348|       |			 */
 3349|       |			if ((tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x7F21, &taglen)) != NULL &&
 3350|       |					cvc_start &&
 3351|       |					cvc_start < tag &&
 3352|       |					cvc_start[0] == 0x7f && cvc_start[1] == 0x21) {
 3353|       |				cvc_len = tag - cvc_start + taglen;
 3354|       |				/* decode the intermediate CVC */
 3355|       |				r = piv_decode_cvc(card, &cvc_start, &cvc_len, &priv->sm_in_cvc);
 3356|       |				if (r < 0) {
 3357|       |					sc_log(card->ctx, "unable to parse intermediate CVC: %d skipping", r);
 3358|       |				}
 3359|       |				priv->sm_flags |= PIV_SM_FLAGS_SM_IN_CVC_PRESENT;
 3360|       |			}
 3361|       |		}
 3362|       |#endif /* ENABLE_PIV_SM */
 3363|       |
 3364|       |		/* convert pub key to internal */
 3365|  2.03k|	} else if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  637|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3365:13): [True: 0, False: 0]
  ------------------
 3366|      0|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, *body, &taglen);
 3367|      0|		if (tag == NULL)
  ------------------
  |  Branch (3367:7): [True: 0, False: 0]
  ------------------
 3368|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3369|       |
 3370|      0|		if (taglen == 0)
  ------------------
  |  Branch (3370:7): [True: 0, False: 0]
  ------------------
 3371|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3372|       |
 3373|      0|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3373:7): [True: 0, False: 0]
  ------------------
 3374|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3375|       |
 3376|      0|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3377|      0|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3378|      0|	} else {
 3379|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3380|      0|	}
 3381|       |
 3382|  2.03k|	sc_log(card->ctx, "added #%d internal %p:%" SC_FORMAT_LEN_SIZE_T "u",
  ------------------
  |  |   71|  2.03k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3383|  2.03k|			enumtag,
 3384|  2.03k|			priv->obj_cache[enumtag].internal_obj_data,
 3385|  2.03k|			priv->obj_cache[enumtag].internal_obj_len);
 3386|       |
 3387|  2.03k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.03k|	int _ret = r; \
  |  |  |  |  155|  2.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.03k|	return _ret; \
  |  |  |  |  163|  2.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3388|  2.03k|}
card-piv.c:piv_finish:
 5379|  10.2k|{
 5380|  10.2k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  10.2k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5381|  10.2k|	int i;
 5382|       |
 5383|  10.2k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.2k]
  |  |  ------------------
  ------------------
 5384|  10.2k|	if (priv) {
  ------------------
  |  Branch (5384:6): [True: 5.60k, False: 4.64k]
  ------------------
 5385|  5.60k|		if (priv->context_specific) {
  ------------------
  |  Branch (5385:7): [True: 0, False: 5.60k]
  ------------------
 5386|      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__
  |  |  ------------------
  ------------------
 5387|      0|			priv->context_specific = 0;
 5388|      0|			sc_unlock(card);
 5389|      0|		}
 5390|  5.60k|		free(priv->aid_der.value);
 5391|  5.60k|		free(priv->al_label);
 5392|  5.60k|		if (priv->w_buf)
  ------------------
  |  Branch (5392:7): [True: 0, False: 5.60k]
  ------------------
 5393|      0|			free(priv->w_buf);
 5394|  5.60k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5394:7): [True: 222, False: 5.38k]
  ------------------
 5395|    222|			free(priv->offCardCertURL);
 5396|   341k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5396:15): [True: 336k, False: 5.60k]
  ------------------
 5397|   336k|			piv_obj_cache_free_entry(card, i, 0);
 5398|   336k|		}
 5399|       |#ifdef ENABLE_PIV_SM
 5400|       |		piv_clear_cvc_content(&priv->sm_cvc);
 5401|       |		piv_clear_cvc_content(&priv->sm_in_cvc);
 5402|       |		piv_clear_sm_session(&priv->sm_session);
 5403|       |#endif /* ENABLE_PIV_SM */
 5404|       |
 5405|  5.60k|		free(priv);
 5406|       |		card->drv_data = NULL; /* priv */
 5407|  5.60k|	}
 5408|  10.2k|	return 0;
 5409|  10.2k|}
card-piv.c:piv_select_file:
 4811|  9.40k|{
 4812|  9.40k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  9.40k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4813|  9.40k|	int r;
 4814|  9.40k|	int i;
 4815|  9.40k|	const u8 *path;
 4816|  9.40k|	size_t pathlen;
 4817|  9.40k|	sc_file_t *file = NULL;
 4818|  9.40k|	u8 *rbuf = NULL;
 4819|  9.40k|	size_t rbuflen = 0;
 4820|       |
 4821|  9.40k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.40k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.40k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.40k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.40k]
  |  |  ------------------
  ------------------
 4822|       |
 4823|  9.40k|	path = in_path->value;
 4824|  9.40k|	pathlen = in_path->len;
 4825|       |
 4826|       |	/* only support single EF in current application */
 4827|       |	/*
 4828|       |	 * PIV emulates files, and only does so because sc_pkcs15_* uses
 4829|       |	 * select_file and read_binary. The emulation adds path emulated structures
 4830|       |	 * so piv_select_file will find it.
 4831|       |	 * there is no dir. Only direct access to emulated files
 4832|       |	 * thus opensc-tool and opensc-explorer can not read the emulated files
 4833|       |	 */
 4834|       |
 4835|  9.40k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (4835:6): [True: 1.19k, False: 8.20k]
  ------------------
 4836|  1.19k|		if (pathlen > 2) {
  ------------------
  |  Branch (4836:7): [True: 1.19k, False: 0]
  ------------------
 4837|  1.19k|			path += 2;
 4838|  1.19k|			pathlen -= 2;
 4839|  1.19k|		}
 4840|  1.19k|	}
 4841|       |
 4842|  9.40k|	i = piv_find_obj_by_containerid(card, path);
 4843|       |
 4844|  9.40k|	if (i < 0)
  ------------------
  |  Branch (4844:6): [True: 1.21k, False: 8.18k]
  ------------------
 4845|  9.40k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  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|  1.21k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.21k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4846|       |
 4847|       |	/*
 4848|       |	 * pkcs15 will use a 2 byte path or a 4 byte path
 4849|       |	 * with cece added to path to request only the cert from the cert obj
 4850|       |	 * PIV "Container ID" is used as the path, and are two bytes long
 4851|       |	 */
 4852|  8.18k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (4852:28): [True: 8.18k, False: 0]
  |  Branch (4852:44): [True: 8.18k, False: 0]
  |  Branch (4852:63): [True: 8.18k, False: 0]
  ------------------
 4853|       |
 4854|  8.18k|	priv->selected_obj = i;
 4855|  8.18k|	priv->rwb_state = -1;
 4856|       |
 4857|       |	/* make it look like the file was found. */
 4858|       |	/* We don't want to read it now  unless we need the length */
 4859|       |
 4860|  8.18k|	if (file_out) {
  ------------------
  |  Branch (4860:6): [True: 8.18k, False: 0]
  ------------------
 4861|       |		/* we need to read it now, to get length into cache */
 4862|  8.18k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 4863|       |
 4864|  8.18k|		if (r < 0)
  ------------------
  |  Branch (4864:7): [True: 6.04k, False: 2.14k]
  ------------------
 4865|  8.18k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  6.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.04k|	int _ret = r; \
  |  |  |  |  155|  6.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.04k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.04k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  6.04k|	return _ret; \
  |  |  |  |  163|  6.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4866|       |
 4867|       |		/* get the cert or the pub key out and into the cache too */
 4868|  2.14k|		if (priv->return_only_cert || piv_objects[i].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  637|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (4868:7): [True: 2.14k, False: 0]
  |  Branch (4868:33): [True: 0, False: 0]
  ------------------
 4869|  2.14k|			r = piv_cache_internal_data(card, i);
 4870|  2.14k|			if (r < 0)
  ------------------
  |  Branch (4870:8): [True: 112, False: 2.03k]
  ------------------
 4871|  2.14k|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    112|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    112|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    112|	int _ret = r; \
  |  |  |  |  155|    112|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 112, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    112|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    112|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 112, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    112|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    112|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    112|	return _ret; \
  |  |  |  |  163|    112|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4872|  2.14k|		}
 4873|       |
 4874|  2.03k|		file = sc_file_new();
 4875|  2.03k|		if (file == NULL)
  ------------------
  |  Branch (4875:7): [True: 0, False: 2.03k]
  ------------------
 4876|  2.03k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4877|       |
 4878|  2.03k|		file->path = *in_path;
 4879|       |		/* this could be like the FCI */
 4880|  2.03k|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|  2.03k|#define SC_FILE_TYPE_DF			0x04
  ------------------
 4881|  2.03k|		file->shareable = 0;
 4882|  2.03k|		file->ef_structure = 0;
 4883|  2.03k|		if (priv->return_only_cert)
  ------------------
  |  Branch (4883:7): [True: 2.03k, False: 0]
  ------------------
 4884|  2.03k|			file->size = priv->obj_cache[i].internal_obj_len;
 4885|      0|		else
 4886|      0|			file->size = priv->obj_cache[i].obj_len;
 4887|       |
 4888|  2.03k|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 4889|       |
 4890|  2.03k|		*file_out = file;
 4891|  2.03k|	}
 4892|       |
 4893|  2.03k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.03k|	int _ret = r; \
  |  |  |  |  155|  2.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.03k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.03k|	return _ret; \
  |  |  |  |  163|  2.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4894|  2.03k|}
card-piv.c:piv_find_obj_by_containerid:
 1762|  68.7k|{
 1763|  68.7k|	int i;
 1764|       |
 1765|  68.7k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  68.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  68.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  68.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  68.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 68.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1766|  68.7k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   71|  68.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__
  |  |  ------------------
  ------------------
 1767|       |
 1768|  1.39M|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1768:14): [True: 1.39M, False: 2.17k]
  ------------------
 1769|  1.39M|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1769:7): [True: 598k, False: 791k]
  |  Branch (1769:50): [True: 66.5k, False: 531k]
  ------------------
 1770|  1.39M|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|  66.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  66.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  66.5k|	int _ret = r; \
  |  |  |  |  155|  66.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 957, False: 65.6k]
  |  |  |  |  ------------------
  |  |  |  |  156|    957|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 957]
  |  |  |  |  ------------------
  |  |  |  |  157|    957|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  65.6k|	} else { \
  |  |  |  |  159|  65.6k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  65.6k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  65.6k|	} \
  |  |  |  |  162|  66.5k|	return _ret; \
  |  |  |  |  163|  66.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1771|  1.39M|	}
 1772|       |
 1773|  2.17k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  2.17k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.17k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.17k|	int _ret = r; \
  |  |  |  |  155|  2.17k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.17k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.17k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.17k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.17k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.17k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.17k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.17k|	return _ret; \
  |  |  |  |  163|  2.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1774|  2.17k|}
card-piv.c:piv_read_binary:
 3397|  2.12k|{
 3398|  2.12k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  2.12k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3399|  2.12k|	int enumtag;
 3400|  2.12k|	int r;
 3401|  2.12k|	u8 *rbuf = NULL;
 3402|  2.12k|	size_t rbuflen = 0;
 3403|  2.12k|	const u8 *body;
 3404|  2.12k|	size_t bodylen;
 3405|       |
 3406|  2.12k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.12k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.12k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.12k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.12k]
  |  |  ------------------
  ------------------
 3407|  2.12k|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3407:6): [True: 0, False: 2.12k]
  ------------------
 3408|  2.12k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3409|  2.12k|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3410|       |
 3411|  2.12k|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3411:6): [True: 2.03k, False: 87]
  ------------------
 3412|  2.03k|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3413|       |
 3414|  2.03k|		if (r >= 0) {
  ------------------
  |  Branch (3414:7): [True: 2.03k, False: 0]
  ------------------
 3415|       |			/* an object with no data will be considered not found */
 3416|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3417|  2.03k|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3417:8): [True: 0, False: 2.03k]
  |  Branch (3417:17): [True: 0, False: 2.03k]
  |  Branch (3417:37): [True: 2.03k, False: 0]
  |  Branch (3417:65): [True: 0, False: 2.03k]
  ------------------
 3418|      0|				r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3419|      0|				goto err;
 3420|      0|			}
 3421|       |
 3422|  2.03k|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3423|  2.03k|			if (body == NULL) {
  ------------------
  |  Branch (3423:8): [True: 0, False: 2.03k]
  ------------------
 3424|       |				/* if missing, assume its the body */
 3425|       |				/* DEE bug in the beta card */
 3426|      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__
  |  |  ------------------
  ------------------
 3427|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3428|      0|				goto err;
 3429|      0|			}
 3430|  2.03k|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3430:8): [True: 0, False: 2.03k]
  ------------------
 3431|      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__
  |  |  ------------------
  ------------------
 3432|      0|						" ***** tag length > then data: %" SC_FORMAT_LEN_SIZE_T "u>%" SC_FORMAT_LEN_PTRDIFF_T "u+%" SC_FORMAT_LEN_SIZE_T "u",
 3433|      0|						bodylen, body - rbuf, rbuflen);
 3434|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3435|      0|				goto err;
 3436|      0|			}
 3437|       |			/* if cached obj has internal interesting data (cert or pub key) */
 3438|  2.03k|			if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  637|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3438:8): [True: 2.03k, False: 0]
  |  Branch (3438:34): [True: 0, False: 0]
  ------------------
 3439|  2.03k|				r = piv_cache_internal_data(card, enumtag);
 3440|  2.03k|				if (r < 0)
  ------------------
  |  Branch (3440:9): [True: 0, False: 2.03k]
  ------------------
 3441|      0|					goto err;
 3442|  2.03k|			}
 3443|  2.03k|		}
 3444|  2.03k|		priv->rwb_state = 0;
 3445|  2.03k|	}
 3446|       |
 3447|  2.12k|	if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  637|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3447:6): [True: 2.12k, False: 0]
  |  Branch (3447:32): [True: 0, False: 0]
  ------------------
 3448|  2.12k|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3449|  2.12k|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3450|  2.12k|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  149|  2.12k|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3450:7): [True: 25, False: 2.09k]
  |  Branch (3450:70): [True: 25, False: 0]
  ------------------
 3451|     25|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     25|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3452|     25|		}
 3453|  2.12k|	} else {
 3454|      0|		rbuf = priv->obj_cache[enumtag].obj_data;
 3455|      0|		rbuflen = priv->obj_cache[enumtag].obj_len;
 3456|      0|	}
 3457|       |	/* rbuf rbuflen has pointer and length to cached data */
 3458|       |
 3459|  2.12k|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3459:6): [True: 0, False: 2.12k]
  ------------------
 3460|      0|		count = rbuflen - idx;
 3461|  2.12k|	if (count <= 0) {
  ------------------
  |  Branch (3461:6): [True: 0, False: 2.12k]
  ------------------
 3462|      0|		r = 0;
 3463|      0|		priv->rwb_state = 1;
 3464|  2.12k|	} else {
 3465|  2.12k|		memcpy(buf, rbuf + idx, count);
 3466|  2.12k|		r = (int)count;
 3467|  2.12k|	}
 3468|       |
 3469|  2.12k|err:
 3470|  2.12k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.12k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.12k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.12k|	int _ret = r; \
  |  |  |  |  155|  2.12k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 2.12k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.12k|	} else { \
  |  |  |  |  159|  2.12k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.12k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.12k|	} \
  |  |  |  |  162|  2.12k|	return _ret; \
  |  |  |  |  163|  2.12k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3471|  2.12k|}
card-piv.c:piv_set_security_env:
 4588|  3.64k|{
 4589|  3.64k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  3.64k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4590|  3.64k|	int r = 0;
 4591|       |
 4592|  3.64k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.64k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.64k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.64k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.64k]
  |  |  ------------------
  ------------------
 4593|       |
 4594|  3.64k|	sc_log(card->ctx,
  ------------------
  |  |   71|  3.64k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4595|  3.64k|			"flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%" SC_FORMAT_LEN_SIZE_T "u",
 4596|  3.64k|			env->flags, env->operation, env->algorithm, env->algorithm_flags,
 4597|  3.64k|			env->algorithm_ref, env->key_ref[0], env->key_ref_len);
 4598|       |
 4599|  3.64k|	priv->operation = env->operation;
 4600|  3.64k|	priv->algorithm = env->algorithm;
 4601|       |
 4602|  3.64k|	if (env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   78|  3.64k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (4602:6): [True: 783, False: 2.86k]
  ------------------
 4603|    783|		priv->alg_id = 0x06; /* Say it is RSA, set 5, 6, 7 later */
 4604|  2.86k|	} else if (env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   79|  2.86k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (4604:13): [True: 2.86k, False: 0]
  ------------------
 4605|  2.86k|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   65|  2.86k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (4605:7): [True: 2.86k, False: 0]
  ------------------
 4606|  2.86k|			switch (env->algorithm_ref) {
 4607|  2.74k|			case 256:
  ------------------
  |  Branch (4607:4): [True: 2.74k, False: 116]
  ------------------
 4608|  2.74k|				priv->alg_id = 0x11; /* Say it is EC 256 */
 4609|  2.74k|				priv->key_size = 256;
 4610|  2.74k|				break;
 4611|    116|			case 384:
  ------------------
  |  Branch (4611:4): [True: 116, False: 2.74k]
  ------------------
 4612|    116|				priv->alg_id = 0x14;
 4613|    116|				priv->key_size = 384;
 4614|    116|				break;
 4615|      0|			default:
  ------------------
  |  Branch (4615:4): [True: 0, False: 2.86k]
  ------------------
 4616|      0|				r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4617|  2.86k|			}
 4618|  2.86k|		} else
 4619|      0|			r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4620|  2.86k|	} else if (env->algorithm == SC_ALGORITHM_EDDSA) {
  ------------------
  |  |   81|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (4620:13): [True: 0, False: 0]
  ------------------
 4621|      0|		priv->alg_id = 0xE0;
 4622|      0|		priv->key_size = 255;
 4623|      0|	} else if (env->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4623:13): [True: 0, False: 0]
  ------------------
 4624|      0|		priv->alg_id = 0xE1;
 4625|      0|		priv->key_size = 255;
 4626|      0|	} else
 4627|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4628|  3.64k|	priv->key_ref = env->key_ref[0];
 4629|       |
 4630|  3.64k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.64k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.64k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.64k|	int _ret = r; \
  |  |  |  |  155|  3.64k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.64k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.64k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.64k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.64k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.64k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.64k|	return _ret; \
  |  |  |  |  163|  3.64k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4631|  3.64k|}
card-piv.c:piv_compute_signature:
 4741|  2.54k|{
 4742|  2.54k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  2.54k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4743|  2.54k|	int r;
 4744|  2.54k|	size_t nLen;
 4745|  2.54k|	u8 rbuf[128]; /* For EC conversions  384 will fit */
 4746|       |
 4747|  2.54k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.54k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.54k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.54k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.54k]
  |  |  ------------------
  ------------------
 4748|       |	/* The PIV returns a DER SEQUENCE{INTEGER, INTEGER}
 4749|       |	 * Which may have leading 00 to force a positive integer
 4750|       |	 * But PKCS11 just wants 2* field_length in bytes
 4751|       |	 * So we have to strip out the integers
 4752|       |	 * and pad on left if too short.
 4753|       |	 */
 4754|       |
 4755|  2.54k|	if (priv->alg_id == 0x11 || priv->alg_id == 0x14) {
  ------------------
  |  Branch (4755:6): [True: 2.34k, False: 197]
  |  Branch (4755:30): [True: 104, False: 93]
  ------------------
 4756|  2.44k|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  146|  2.44k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4757|  2.44k|		if (outlen < 2 * nLen) {
  ------------------
  |  Branch (4757:7): [True: 0, False: 2.44k]
  ------------------
 4758|      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__
  |  |  ------------------
  ------------------
 4759|      0|					" output too small for EC signature %" SC_FORMAT_LEN_SIZE_T "u < %" SC_FORMAT_LEN_SIZE_T "u",
 4760|      0|					outlen, 2 * nLen);
 4761|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4762|      0|			goto err;
 4763|      0|		}
 4764|       |
 4765|  2.44k|		r = piv_validate_general_authentication(card, data, datalen, rbuf, sizeof rbuf);
 4766|  2.44k|		if (r < 0)
  ------------------
  |  Branch (4766:7): [True: 2.25k, False: 192]
  ------------------
 4767|  2.25k|			goto err;
 4768|       |
 4769|    192|		r = sc_asn1_decode_ecdsa_signature(card->ctx, rbuf, r, nLen, &out, outlen);
 4770|       |		/* Yubikey 5.7.x supports ED25519 */
 4771|    192|	} else if (priv->alg_id == 0xE0) {
  ------------------
  |  Branch (4771:13): [True: 0, False: 93]
  ------------------
 4772|      0|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  146|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4773|      0|		if (outlen < nLen) {
  ------------------
  |  Branch (4773:7): [True: 0, False: 0]
  ------------------
 4774|      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__
  |  |  ------------------
  ------------------
 4775|      0|					" output too small for ED signature %" SC_FORMAT_LEN_SIZE_T "u < %" SC_FORMAT_LEN_SIZE_T "u",
 4776|      0|					outlen, nLen);
 4777|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4778|      0|			goto err;
 4779|      0|		}
 4780|      0|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4781|       |
 4782|     93|	} else { /* RSA is all set */
 4783|     93|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4784|     93|	}
 4785|       |
 4786|  2.54k|err:
 4787|  2.54k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.54k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.54k|	int _ret = r; \
  |  |  155|  2.54k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.54k, False: 0]
  |  |  ------------------
  |  |  156|  2.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|  2.54k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.54k, False: 0]
  |  |  ------------------
  |  |  157|  2.54k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.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|  2.54k|	return _ret; \
  |  |  163|  2.54k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4788|  2.54k|}
card-piv.c:piv_validate_general_authentication:
 4645|  3.15k|{
 4646|  3.15k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  3.15k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4647|  3.15k|	int r, tmplen, tmplen2;
 4648|  3.15k|	u8 *p;
 4649|  3.15k|	const unsigned char *p2;
 4650|  3.15k|	size_t taglen;
 4651|  3.15k|	size_t bodylen;
 4652|  3.15k|	unsigned int cla, tag;
 4653|  3.15k|	unsigned int real_alg_id, op_tag;
 4654|       |
 4655|  3.15k|	u8 sbuf[4096]; /* needs work. for 4096 needs 512+10 or so */
 4656|  3.15k|	size_t sbuflen = sizeof(sbuf);
 4657|  3.15k|	u8 rbuf[4096];
 4658|       |
 4659|  3.15k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.15k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.15k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.15k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.15k]
  |  |  ------------------
  ------------------
 4660|       |
 4661|       |	/* should assume large send data */
 4662|  3.15k|	p = sbuf;
 4663|  3.15k|	tmplen = sc_asn1_put_tag(0xff, NULL, datalen, NULL, 0, NULL);
 4664|  3.15k|	tmplen2 = sc_asn1_put_tag(0x82, NULL, 0, NULL, 0, NULL);
 4665|  3.15k|	if (tmplen <= 0 || tmplen2 <= 0) {
  ------------------
  |  Branch (4665:6): [True: 0, False: 3.15k]
  |  Branch (4665:21): [True: 0, False: 3.15k]
  ------------------
 4666|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4667|      0|	}
 4668|  3.15k|	tmplen += tmplen2;
 4669|  3.15k|	if ((r = sc_asn1_put_tag(0x7c, NULL, tmplen, p, sbuflen, &p)) != SC_SUCCESS ||
  ------------------
  |  |   28|  6.31k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4669:6): [True: 70, False: 3.08k]
  ------------------
 4670|  3.08k|			(r = sc_asn1_put_tag(0x82, NULL, 0, p, sbuflen - (p - sbuf), &p)) != SC_SUCCESS) {
  ------------------
  |  |   28|  3.08k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4670:4): [True: 0, False: 3.08k]
  ------------------
 4671|     70|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     70|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     70|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     70|	int _ret = r; \
  |  |  |  |  155|     70|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     70|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4672|     70|	}
 4673|  3.08k|	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   59|  6.17k|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   79|    322|#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 (4673:6): [True: 161, False: 2.92k]
  |  Branch (4673:53): [True: 161, False: 0]
  |  Branch (4673:91): [True: 0, False: 0]
  ------------------
 4674|    161|		op_tag = 0x85;
 4675|  2.92k|	} else {
 4676|  2.92k|		op_tag = 0x81;
 4677|  2.92k|	}
 4678|  3.08k|	r = sc_asn1_put_tag(op_tag, data, datalen, p, sbuflen - (p - sbuf), &p);
 4679|  3.08k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  3.08k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4679:6): [True: 0, False: 3.08k]
  ------------------
 4680|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4681|      0|	}
 4682|       |
 4683|       |	/*
 4684|       |	 * alg_id=06 is a place holder for all RSA keys.
 4685|       |	 * Derive the real alg_id based on the size of the
 4686|       |	 * the data, as we are always using raw mode.
 4687|       |	 * Non RSA keys needs some work in this area.
 4688|       |	 */
 4689|       |
 4690|  3.08k|	real_alg_id = priv->alg_id;
 4691|  3.08k|	if (priv->alg_id == 0x06) {
  ------------------
  |  Branch (4691:6): [True: 479, False: 2.60k]
  ------------------
 4692|    479|		switch (datalen) {
 4693|    157|		case 128:
  ------------------
  |  Branch (4693:3): [True: 157, False: 322]
  ------------------
 4694|    157|			real_alg_id = 0x06;
 4695|    157|			break;
 4696|     30|		case 256:
  ------------------
  |  Branch (4696:3): [True: 30, False: 449]
  ------------------
 4697|     30|			real_alg_id = 0x07;
 4698|     30|			break;
 4699|     34|		case 384:
  ------------------
  |  Branch (4699:3): [True: 34, False: 445]
  ------------------
 4700|     34|			real_alg_id = 0x05;
 4701|     34|			break;
 4702|     62|		case 512:
  ------------------
  |  Branch (4702:3): [True: 62, False: 417]
  ------------------
 4703|     62|			real_alg_id = 0x16;
 4704|     62|			break;
 4705|    196|		default:
  ------------------
  |  Branch (4705:3): [True: 196, False: 283]
  ------------------
 4706|    196|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  153|    196|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    196|	int _ret = r; \
  |  |  155|    196|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 196, False: 0]
  |  |  ------------------
  |  |  156|    196|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    196|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 196, False: 0]
  |  |  ------------------
  |  |  157|    196|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    196|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    196|	return _ret; \
  |  |  163|    196|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4707|    479|		}
 4708|    479|	}
 4709|       |	/* EC and ED alg_id was already set */
 4710|       |
 4711|  2.89k|	r = piv_general_io(card, 0x87, real_alg_id, priv->key_ref,
 4712|  2.89k|			sbuf, p - sbuf, rbuf, sizeof rbuf);
 4713|  2.89k|	if (r < 0)
  ------------------
  |  Branch (4713:6): [True: 2.45k, False: 433]
  ------------------
 4714|  2.45k|		goto err;
 4715|       |
 4716|    433|	p2 = rbuf;
 4717|    433|	r = sc_asn1_read_tag(&p2, r, &cla, &tag, &bodylen);
 4718|    433|	if (p2 == NULL || r < 0 || bodylen == 0 || (cla | tag) != 0x7C) {
  ------------------
  |  Branch (4718:6): [True: 154, False: 279]
  |  Branch (4718:20): [True: 88, False: 191]
  |  Branch (4718:29): [True: 104, False: 87]
  |  Branch (4718:45): [True: 70, False: 17]
  ------------------
 4719|    416|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x7C");
  ------------------
  |  |  184|    416|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    416|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    416|	int _ret = (r); \
  |  |  |  |  178|    416|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 416, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    416|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    416|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    416|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    416|		goto err; \
  |  |  |  |  182|    416|	} \
  |  |  |  |  183|    416|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4720|    416|	}
 4721|       |
 4722|     17|	r = sc_asn1_read_tag(&p2, bodylen, &cla, &tag, &taglen);
 4723|     17|	if (p2 == NULL || r < 0 || taglen == 0 || (cla | tag) != 0x82) {
  ------------------
  |  Branch (4723:6): [True: 1, False: 16]
  |  Branch (4723:20): [True: 1, False: 15]
  |  Branch (4723:29): [True: 1, False: 14]
  |  Branch (4723:44): [True: 1, False: 13]
  ------------------
 4724|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4725|      4|	}
 4726|       |
 4727|     13|	if (taglen > outlen) {
  ------------------
  |  Branch (4727:6): [True: 0, False: 13]
  ------------------
 4728|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4729|      0|	}
 4730|       |
 4731|     13|	memcpy(out, p2, taglen);
 4732|     13|	r = (int)taglen;
 4733|       |
 4734|  2.89k|err:
 4735|  2.89k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.89k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.89k|	int _ret = r; \
  |  |  |  |  155|  2.89k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.87k, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|  2.67k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.67k, False: 202]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.87k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.87k|	} 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|  2.89k|	return _ret; \
  |  |  |  |  163|  2.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4736|  2.89k|}
card-piv.c:piv_decipher:
 4792|    617|{
 4793|    617|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    617|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    617|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    617|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 617]
  |  |  ------------------
  ------------------
 4794|       |
 4795|    617|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, piv_validate_general_authentication(card, data, datalen, out, outlen));
  ------------------
  |  |  153|    617|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    617|	int _ret = r; \
  |  |  155|    617|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 616, False: 1]
  |  |  ------------------
  |  |  156|    616|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    594|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 594, False: 22]
  |  |  ------------------
  |  |  157|    616|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    616|	} 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|    617|	return _ret; \
  |  |  163|    617|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4796|    617|}
card-piv.c:piv_check_sw:
 6073|  34.7k|{
 6074|  34.7k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6075|       |
 6076|  34.7k|	int r;
 6077|       |#ifdef ENABLE_PIV_SM
 6078|       |	int i;
 6079|       |#endif
 6080|  34.7k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  34.7k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6081|       |
 6082|  34.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  34.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  34.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  34.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 34.7k]
  |  |  ------------------
  ------------------
 6083|       |
 6084|       |	/* may be called before piv_init has allocated priv */
 6085|  34.7k|	if (priv) {
  ------------------
  |  Branch (6085:6): [True: 34.7k, False: 0]
  ------------------
 6086|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6087|       |
 6088|  34.7k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6088:7): [True: 3.17k, False: 31.5k]
  ------------------
 6089|  3.17k|			priv->pin_cmd_verify_sw1 = sw1;
 6090|  3.17k|			priv->pin_cmd_verify_sw2 = sw2;
 6091|  31.5k|		} else {
 6092|       |			/* a command has completed and it is not verify
 6093|       |			 * If we are in a context_specific sequence, unlock
 6094|       |			 * This just decrements the extra lock count
 6095|       |			 */
 6096|  31.5k|			if (priv->context_specific) {
  ------------------
  |  Branch (6096:8): [True: 0, False: 31.5k]
  ------------------
 6097|      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__
  |  |  ------------------
  ------------------
 6098|      0|				priv->context_specific = 0;
 6099|      0|				sc_unlock(card);
 6100|      0|			}
 6101|  31.5k|		}
 6102|       |
 6103|  34.7k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  576|  34.7k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6103:7): [True: 11.3k, False: 23.4k]
  ------------------
 6104|       |
 6105|       |			/* Handle the Yubikey NEO or any other PIV card which returns in response to a verify
 6106|       |			 * 63 0X rather than 63 CX indicate the number of remaining PIN retries.
 6107|       |			 * Perhaps they misread the spec and thought 0xCX meant "clear" or "don't care", not a literal 0xC!
 6108|       |			 */
 6109|  11.3k|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6109:8): [True: 1.43k, False: 9.89k]
  |  Branch (6109:32): [True: 40, False: 1.39k]
  ------------------
 6110|     40|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6111|     40|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6111:9): [True: 17, False: 23]
  ------------------
 6112|     17|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6113|     17|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     17|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6114|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6115|     17|				}
 6116|     40|			}
 6117|  11.3k|		}
 6118|  34.7k|	}
 6119|       |#ifdef ENABLE_PIV_SM
 6120|       |	/* Note 6982 is map to SC_ERROR_SM_NO_SESSION_KEYS but iso maps it to SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
 6121|       |	/* we do this because 6982 could also mean a verify is not allowed over contactless without VCI */
 6122|       |	/* we stashed the sw1 and sw2 above for verify */
 6123|       |	/* Check specific NIST sp800-73-4 SM  errors */
 6124|       |	for (i = 0; piv_sm_errors[i].SWs != 0; i++) {
 6125|       |		if (piv_sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
 6126|       |			sc_log(card->ctx, "%s", piv_sm_errors[i].errorstr);
 6127|       |			return piv_sm_errors[i].errorno;
 6128|       |		}
 6129|       |	}
 6130|       |#endif
 6131|  34.7k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6132|  34.7k|	return r;
 6133|  34.7k|}
card-piv.c:piv_card_ctl:
 4487|  61.2k|{
 4488|  61.2k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  61.2k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4489|  61.2k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4490|       |
 4491|  61.2k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  61.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  61.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  61.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  61.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 61.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4492|       |
 4493|  61.2k|	if (priv == NULL) {
  ------------------
  |  Branch (4493:6): [True: 0, False: 61.2k]
  ------------------
 4494|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4495|      0|	}
 4496|  61.2k|	switch (cmd) {
  ------------------
  |  Branch (4496:10): [True: 61.2k, False: 0]
  ------------------
 4497|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4497:2): [True: 0, False: 61.2k]
  ------------------
 4498|      0|		opts = (u8 *)ptr;
 4499|      0|		switch (*opts) {
  ------------------
  |  Branch (4499:11): [True: 0, False: 0]
  ------------------
 4500|      0|		case 'A':
  ------------------
  |  Branch (4500:3): [True: 0, False: 0]
  ------------------
 4501|      0|			return piv_general_external_authenticate(card,
 4502|      0|					*(opts + 1), *(opts + 2));
 4503|      0|			break;
 4504|      0|		case 'M':
  ------------------
  |  Branch (4504:3): [True: 0, False: 0]
  ------------------
 4505|      0|			return piv_general_mutual_authenticate(card,
 4506|      0|					*(opts + 1), *(opts + 2));
 4507|      0|			break;
 4508|      0|		}
 4509|      0|		break;
 4510|      0|	case SC_CARDCTL_PIV_GENERATE_KEY:
  ------------------
  |  Branch (4510:2): [True: 0, False: 61.2k]
  ------------------
 4511|      0|		return piv_generate_key(card,
 4512|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4513|      0|		break;
 4514|    957|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4514:2): [True: 957, False: 60.2k]
  ------------------
 4515|    957|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4516|      0|		break;
 4517|    957|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4517:2): [True: 957, False: 60.2k]
  ------------------
 4518|    957|		return piv_get_pin_preference(card, ptr);
 4519|      0|		break;
 4520|  59.3k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4520:2): [True: 59.3k, False: 1.91k]
  ------------------
 4521|  59.3k|		return piv_is_object_present(card, ptr);
 4522|      0|		break;
 4523|  61.2k|	}
 4524|       |
 4525|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4526|      0|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4366|    957|{
 4367|    957|	int r;
 4368|    957|	int i;
 4369|    957|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4370|    957|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4371|    957|	u8 *rbuf = NULL;
 4372|    957|	const u8 *body;
 4373|    957|	const u8 *fascn;
 4374|    957|	const u8 *guid;
 4375|    957|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4376|       |
 4377|    957|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    957|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    957|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    957|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 957]
  |  |  ------------------
  ------------------
 4378|    957|	if (card->serialnr.len) {
  ------------------
  |  Branch (4378:6): [True: 0, False: 957]
  ------------------
 4379|      0|		*serial = card->serialnr;
 4380|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4381|      0|	}
 4382|       |
 4383|       |	/*
 4384|       |	 * 800-73-3 Part 1 and CIO Council docs say for PIV Compatible cards
 4385|       |	 * the FASC-N Agency code should be 9999 and there should be a GUID
 4386|       |	 * based on RFC 4122. If GUID present and not zero
 4387|       |	 * we will use the GUID as the serial number.
 4388|       |	 */
 4389|       |
 4390|    957|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4391|    957|	LOG_TEST_RET(card->ctx, r, "Failure retrieving CHUI");
  ------------------
  |  |  174|    957|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    957|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    957|	int _ret = (r); \
  |  |  |  |  168|    957|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 876, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  169|    876|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    876|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    876|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    876|		return _ret; \
  |  |  |  |  172|    876|	} \
  |  |  |  |  173|    957|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4392|       |
 4393|     81|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     81|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4394|     81|	if (rbuflen != 0) {
  ------------------
  |  Branch (4394:6): [True: 81, False: 0]
  ------------------
 4395|     81|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4396|     81|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4396:7): [True: 81, False: 0]
  |  Branch (4396:23): [True: 76, False: 5]
  |  Branch (4396:39): [True: 76, False: 0]
  ------------------
 4397|     76|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4398|       |
 4399|     76|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4399:8): [True: 45, False: 31]
  |  Branch (4399:17): [True: 41, False: 4]
  ------------------
 4400|  1.06k|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4400:17): [True: 1.02k, False: 41]
  ------------------
 4401|  1.02k|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4401:14): [True: 855, False: 170]
  |  Branch (4401:23): [True: 40, False: 130]
  ------------------
 4402|  1.02k|				}
 4403|     41|			}
 4404|       |
 4405|     76|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4406|       |
 4407|     76|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4407:8): [True: 17, False: 59]
  |  Branch (4407:16): [True: 13, False: 4]
  ------------------
 4408|    221|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4408:17): [True: 208, False: 13]
  ------------------
 4409|    208|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4410|    208|				}
 4411|     13|			}
 4412|     76|			sc_log(card->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__
  |  |  ------------------
  ------------------
 4413|     76|					"fascn=%p,fascnlen=%" SC_FORMAT_LEN_SIZE_T "u,guid=%p,guidlen=%" SC_FORMAT_LEN_SIZE_T "u,gbits=%2.2x",
 4414|     76|					fascn, fascnlen, guid, guidlen, gbits);
 4415|       |
 4416|     76|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4416:8): [True: 45, False: 31]
  |  Branch (4416:17): [True: 41, False: 4]
  |  Branch (4416:35): [True: 40, False: 1]
  ------------------
 4417|       |				/* test if guid and the fascn starts with ;9999 (in ISO 4bit + parity code) */
 4418|       |				/* ;9999 is non-gov issued FASC-N, will use FASC-N for gov issued if no guid */
 4419|     40|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4419:11): [True: 12, False: 28]
  |  Branch (4419:20): [True: 4, False: 8]
  |  Branch (4419:40): [True: 3, False: 1]
  ------------------
 4420|     39|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4420:11): [True: 2, False: 1]
  |  Branch (4420:31): [True: 1, False: 1]
  ------------------
 4421|       |					/* fascnlen is 25 */
 4422|     39|					serial->len = fascnlen;
 4423|     39|					memcpy(serial->value, fascn, serial->len);
 4424|     39|					r = SC_SUCCESS;
  ------------------
  |  |   28|     39|#define SC_SUCCESS				0
  ------------------
 4425|     39|					gbits = 0; /* set to skip using guid below */
 4426|     39|				}
 4427|     40|			}
 4428|     76|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4428:8): [True: 17, False: 59]
  |  Branch (4428:16): [True: 13, False: 4]
  |  Branch (4428:33): [True: 2, False: 11]
  ------------------
 4429|      2|				serial->len = guidlen;
 4430|      2|				memcpy(serial->value, guid, serial->len);
 4431|      2|				r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 4432|      2|			}
 4433|     76|		}
 4434|     81|	}
 4435|       |
 4436|     81|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4436:6): [True: 41, False: 40]
  |  Branch (4436:20): [True: 40, False: 1]
  ------------------
 4437|     40|		serial->len = 16;
 4438|     40|		memset(serial->value, 0x00, serial->len);
 4439|     40|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     40|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4440|     40|	}
 4441|       |
 4442|     81|	card->serialnr = *serial;
 4443|     81|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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|     40|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 40, False: 41]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4444|     81|}
card-piv.c:piv_get_pin_preference:
 4478|    957|{
 4479|    957|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    957|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4480|       |
 4481|    957|	*pin_ref = priv->pin_preference;
 4482|    957|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    957|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    957|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    957|	int _ret = r; \
  |  |  |  |  155|    957|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 957, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    957|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 957]
  |  |  |  |  ------------------
  |  |  |  |  157|    957|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    957|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    957|	return _ret; \
  |  |  |  |  163|    957|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4483|    957|}
card-piv.c:piv_is_object_present:
 4459|  59.3k|{
 4460|  59.3k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  59.3k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4461|  59.3k|	int r = 0;
 4462|  59.3k|	int enumtag;
 4463|       |
 4464|  59.3k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4465|  59.3k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  150|  58.3k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4465:6): [True: 58.3k, False: 957]
  |  Branch (4465:22): [True: 32.7k, False: 25.6k]
  ------------------
 4466|  32.7k|		r = 1;
 4467|       |
 4468|  59.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  59.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  59.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  59.3k|	int _ret = r; \
  |  |  |  |  155|  59.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26.6k, False: 32.7k]
  |  |  |  |  ------------------
  |  |  |  |  156|  26.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 26.6k]
  |  |  |  |  ------------------
  |  |  |  |  157|  26.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  32.7k|	} else { \
  |  |  |  |  159|  32.7k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  32.7k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  32.7k|	} \
  |  |  |  |  162|  59.3k|	return _ret; \
  |  |  |  |  163|  59.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4469|  59.3k|}
card-piv.c:piv_pin_cmd:
 6206|  2.31k|{
 6207|  2.31k|	int r = 0;
 6208|  2.31k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  2.31k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6209|       |
 6210|       |	/* Extra validation of (new) PIN during a PIN change request, to
 6211|       |	 * ensure it's not outside the FIPS 201 4.1.6.1 (numeric only) and
 6212|       |	 * FIPS 140-2 (6 character minimum) requirements.
 6213|       |	 */
 6214|  2.31k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6215|       |
 6216|  2.31k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.31k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.31k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.31k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.31k]
  |  |  ------------------
  ------------------
 6217|  2.31k|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|  2.31k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6218|  2.31k|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  423|  2.31k|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (6218:6): [True: 120, False: 2.19k]
  ------------------
 6219|    120|		size_t i = 0;
 6220|    120|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (6220:7): [True: 38, False: 82]
  ------------------
 6221|     38|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|     38|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 6222|     38|		}
 6223|    432|		for (i = 0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (6223:15): [True: 390, False: 42]
  ------------------
 6224|    390|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (6224:8): [True: 40, False: 350]
  ------------------
 6225|     40|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     40|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 6226|     40|			}
 6227|    390|		}
 6228|     82|	}
 6229|       |
 6230|  2.23k|	priv->pin_cmd_verify_sw1 = 0x00U;
 6231|       |
 6232|  2.23k|	if (data->cmd == SC_PIN_CMD_GET_INFO) { /* fill in what we think it should be */
  ------------------
  |  |  425|  2.23k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6232:6): [True: 1.89k, False: 340]
  ------------------
 6233|  1.89k|		data->pin1.logged_in = priv->logged_in;
 6234|  1.89k|		data->pin1.tries_left = priv->tries_left;
 6235|       |
 6236|       |		/*
 6237|       |		 * If called to check on the login state for a context specific login
 6238|       |		 * return not logged in. Needed because of logic in e6f7373ef066
 6239|       |		 */
 6240|  1.89k|		if (data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|  1.89k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6240:7): [True: 0, False: 1.89k]
  ------------------
 6241|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6242|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6243|      0|		}
 6244|       |
 6245|  1.89k|		if (priv->logged_in & SC_PIN_STATE_LOGGED_IN) {
  ------------------
  |  |  439|  1.89k|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  |  Branch (6245:7): [True: 57, False: 1.83k]
  ------------------
 6246|       |			/* Avoid status requests when the user is logged in to handle NIST
 6247|       |			 * 800-73-4 Part 2:
 6248|       |			 * The PKI cryptographic function (see Table 4b) is protected with
 6249|       |			 * a “PIN Always” or “OCC Always” access rule. In other words, the
 6250|       |			 * PIN or OCC data must be submitted and verified every time
 6251|       |			 * immediately before a digital signature key operation.  This
 6252|       |			 * ensures cardholder participation every time the private key is
 6253|       |			 * used for digital signature generation */
 6254|     57|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     57|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     57|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     57|	int _ret = r; \
  |  |  |  |  155|     57|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  157|     57|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     57|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     57|	return _ret; \
  |  |  |  |  163|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6255|     57|		}
 6256|  1.89k|	}
 6257|       |
 6258|       |	/*
 6259|       |	 * If this was for a CKU_CONTEXT_SPECFIC login, lock the card one more time.
 6260|       |	 * to avoid any interference from other applications.
 6261|       |	 * Sc_unlock will be called at a later time after the next card command
 6262|       |	 * that should be a crypto operation. If its not then it is a error by the
 6263|       |	 * calling application.
 6264|       |	 */
 6265|  2.17k|	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  422|  4.35k|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|    178|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6265:6): [True: 178, False: 1.99k]
  |  Branch (6265:40): [True: 0, False: 178]
  ------------------
 6266|      0|		priv->context_specific = 1;
 6267|      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__
  |  |  ------------------
  ------------------
 6268|      0|		r = sc_lock(card);
 6269|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (6269:7): [True: 0, False: 0]
  ------------------
 6270|      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__
  |  |  ------------------
  ------------------
 6271|      0|			return r;
 6272|      0|		}
 6273|      0|	}
 6274|       |
 6275|  2.17k|	priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6276|  2.17k|	r = iso_drv->ops->pin_cmd(card, data);
 6277|  2.17k|	priv->pin_cmd_verify = 0;
 6278|       |
 6279|       |	/* tell user verify not supported on contactless without VCI */
 6280|  2.17k|	if (priv->pin_cmd_verify_sw1 == 0x69 && priv->pin_cmd_verify_sw2 == 0x82 &&
  ------------------
  |  Branch (6280:6): [True: 42, False: 2.13k]
  |  Branch (6280:42): [True: 24, False: 18]
  ------------------
 6281|     24|			priv->init_flags & PIV_INIT_CONTACTLESS &&
  ------------------
  |  |  382|  2.20k|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (6281:4): [True: 11, False: 13]
  ------------------
 6282|     11|			card->type == SC_CARD_TYPE_PIV_II_800_73_4) {
  ------------------
  |  Branch (6282:4): [True: 0, False: 11]
  ------------------
 6283|      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__
  |  |  ------------------
  ------------------
 6284|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 6285|      0|	}
 6286|       |
 6287|       |	/* if verify failed, release the lock */
 6288|  2.17k|	if (data->cmd == SC_PIN_CMD_VERIFY && r < 0 && priv->context_specific) {
  ------------------
  |  |  422|  4.35k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6288:6): [True: 178, False: 1.99k]
  |  Branch (6288:40): [True: 153, False: 25]
  |  Branch (6288:49): [True: 0, False: 153]
  ------------------
 6289|      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__
  |  |  ------------------
  ------------------
 6290|      0|		priv->context_specific = 0;
 6291|      0|		sc_unlock(card);
 6292|      0|	}
 6293|       |
 6294|       |	/* if access to applet is know to be reset by other driver  we select_aid and try again */
 6295|  2.17k|	if (priv->card_issues & CI_OTHER_AID_LOSE_STATE && priv->pin_cmd_verify_sw1 == 0x6DU) {
  ------------------
  |  |  585|  4.35k|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
  |  Branch (6295:6): [True: 1.12k, False: 1.04k]
  |  Branch (6295:53): [True: 1.00k, False: 126]
  ------------------
 6296|  1.00k|		sc_log(card->ctx, "AID may be lost doing piv_find_aid and retry pin_cmd");
  ------------------
  |  |   71|  1.00k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6297|  1.00k|		piv_find_aid(card);
 6298|       |
 6299|  1.00k|		priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6300|  1.00k|		r = iso_drv->ops->pin_cmd(card, data);
 6301|  1.00k|		priv->pin_cmd_verify = 0;
 6302|  1.00k|	}
 6303|       |
 6304|       |	/* If verify worked, we are logged_in */
 6305|  2.17k|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  422|  2.17k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6305:6): [True: 178, False: 1.99k]
  ------------------
 6306|    178|		if (r >= 0)
  ------------------
  |  Branch (6306:7): [True: 26, False: 152]
  ------------------
 6307|     26|			priv->logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|     26|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6308|    152|		else
 6309|    152|			priv->logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|    152|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6310|    178|	}
 6311|       |
 6312|       |	/* Some cards never return 90 00  for SC_PIN_CMD_GET_INFO even if the card state is verified */
 6313|       |	/* PR 797 has changed the return codes from pin_cmd, and added a data->pin1.logged_in flag */
 6314|       |
 6315|  2.17k|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  425|  2.17k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6315:6): [True: 1.83k, False: 340]
  ------------------
 6316|  1.83k|		if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) {
  ------------------
  |  |  580|  1.83k|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6316:7): [True: 5, False: 1.83k]
  ------------------
 6317|      5|			sc_log(card->ctx, "CI_CANT_USE_GETDATA_FOR_STATE set, assume logged_in=%d", priv->logged_in);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6318|      5|			data->pin1.logged_in = priv->logged_in; /* use what ever we saw last */
 6319|  1.83k|		} else if (priv->card_issues & CI_VERIFY_LC0_FAIL &&
  ------------------
  |  |  577|  3.66k|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
  |  Branch (6319:14): [True: 601, False: 1.23k]
  ------------------
 6320|    601|				priv->pin_cmd_verify_sw1 == 0x63U) { /* can not use modified return codes from iso->drv->pin_cmd */
  ------------------
  |  Branch (6320:5): [True: 17, False: 584]
  ------------------
 6321|       |			/* try another method, looking at a protected object this may require adding one of these to NEO */
 6322|     17|			r = piv_check_protected_objects(card);
 6323|     17|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  |  Branch (6323:8): [True: 1, False: 16]
  ------------------
 6324|      1|				data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|      1|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6325|     16|			else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|     16|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (6325:13): [True: 14, False: 2]
  ------------------
 6326|     14|				if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) { /* we still can not determine login state */
  ------------------
  |  |  580|     14|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6326:9): [True: 5, False: 9]
  ------------------
 6327|       |
 6328|      5|					data->pin1.logged_in = priv->logged_in; /* may have be set from SC_PIN_CMD_VERIFY */
 6329|      9|				} else {
 6330|      9|					data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|      9|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6331|      9|				}
 6332|     14|				r = SC_SUCCESS;
  ------------------
  |  |   28|     14|#define SC_SUCCESS				0
  ------------------
 6333|     14|			}
 6334|     17|		}
 6335|  1.83k|		priv->logged_in = data->pin1.logged_in;
 6336|  1.83k|		priv->tries_left = data->pin1.tries_left;
 6337|  1.83k|	}
 6338|       |
 6339|  2.17k|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
 6340|  2.17k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.17k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.17k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.17k|	int _ret = r; \
  |  |  |  |  155|  2.17k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.17k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.17k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.06k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.06k, False: 108]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.17k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.17k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.17k|	return _ret; \
  |  |  |  |  163|  2.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6341|  2.17k|}
card-piv.c:piv_check_protected_objects:
 6137|     17|{
 6138|     17|	int r = 0;
 6139|     17|	int i;
 6140|     17|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|     17|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6141|     17|	u8 buf[8]; /* tag of 53 with 82 xx xx  will fit in 4 */
 6142|     17|	u8 *rbuf;
 6143|     17|	size_t buf_len;
 6144|     17|	static int protected_objects[] = {PIV_OBJ_PI, PIV_OBJ_CHF, PIV_OBJ_IRIS_IMAGE};
 6145|       |
 6146|     17|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     17|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     17|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     17|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     17|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6147|       |	/*
 6148|       |	 * routine only called from piv_pin_cmd after verify lc=0 did not return 90 00
 6149|       |	 * We will test for a protected object using GET DATA.
 6150|       |	 *
 6151|       |	 * Based on observations, of cards using the GET DATA APDU,
 6152|       |	 * SC_ERROR_SECURITY_STATUS_NOT_SATISFIED  means the PIN not verified,
 6153|       |	 * SC_SUCCESS means PIN has been verified even if it has length 0
 6154|       |	 * SC_ERROR_FILE_NOT_FOUND (which is the bug) does not tell us anything
 6155|       |	 * about the state of the PIN and we will try the next object.
 6156|       |	 *
 6157|       |	 * If we can't determine the security state from this process,
 6158|       |	 * set card_issues CI_CANT_USE_GETDATA_FOR_STATE
 6159|       |	 * and return SC_ERROR_PIN_CODE_INCORRECT
 6160|       |	 * The circumvention is to add a dummy Printed Info object in the card.
 6161|       |	 * so we will have an object to test.
 6162|       |	 *
 6163|       |	 * We save the object's number to use in the future.
 6164|       |	 *
 6165|       |	 */
 6166|     17|	if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6166:6): [True: 13, False: 4]
  ------------------
 6167|     33|		for (i = 0; i < (int)(sizeof(protected_objects) / sizeof(int)); i++) {
  ------------------
  |  Branch (6167:15): [True: 28, False: 5]
  ------------------
 6168|     28|			buf_len = sizeof(buf);
 6169|     28|			rbuf = buf;
 6170|     28|			r = piv_get_data(card, protected_objects[i], &rbuf, &buf_len);
 6171|     28|			if (r >= 0 || r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|     27|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6171:8): [True: 1, False: 27]
  |  Branch (6171:18): [True: 7, False: 20]
  ------------------
 6172|       |
 6173|       |				/* we can use this object next time if needed */
 6174|      8|				priv->object_test_verify = protected_objects[i];
 6175|      8|				break;
 6176|      8|			}
 6177|     28|		}
 6178|     13|		if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6178:7): [True: 5, False: 8]
  ------------------
 6179|       |			/*
 6180|       |			 * none of the objects returned acceptable sw1, sw2
 6181|       |			 */
 6182|      5|			sc_log(card->ctx, "No protected objects found, setting CI_CANT_USE_GETDATA_FOR_STATE");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6183|      5|			priv->card_issues |= CI_CANT_USE_GETDATA_FOR_STATE;
  ------------------
  |  |  580|      5|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
 6184|      5|			r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      5|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6185|      5|		}
 6186|     13|	} else {
 6187|       |		/* use the one object we found earlier. Test is security status has changed */
 6188|      4|		buf_len = sizeof(buf);
 6189|      4|		rbuf = buf;
 6190|      4|		r = piv_get_data(card, priv->object_test_verify, &rbuf, &buf_len);
 6191|      4|	}
 6192|     17|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|     17|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (6192:6): [True: 1, False: 16]
  ------------------
 6193|      1|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      1|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6194|     16|	else if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|     16|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6194:11): [True: 8, False: 8]
  ------------------
 6195|      8|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      8|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6196|      8|	else if (r > 0)
  ------------------
  |  Branch (6196:11): [True: 1, False: 7]
  ------------------
 6197|      1|		r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 6198|       |
 6199|     17|	sc_log(card->ctx, "card->type:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6200|     17|			card->type, priv->card_issues, r, priv->alg_ids);
 6201|     17|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6202|     17|}
card-piv.c:piv_card_reader_lock_obtained:
 6380|  13.4k|{
 6381|  13.4k|	int r = 0;
 6382|  13.4k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6383|  13.4k|	size_t templen = sizeof(temp);
 6384|  13.4k|	piv_private_data_t *priv = PIV_DATA(card); /* may be null */
  ------------------
  |  |  432|  13.4k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6385|       |
 6386|  13.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  13.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  13.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  13.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 13.4k]
  |  |  ------------------
  ------------------
 6387|       |
 6388|       |	/* We have a PCSC transaction and sc_lock */
 6389|  13.4k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6389:6): [True: 5.60k, False: 7.85k]
  |  Branch (6389:22): [True: 957, False: 6.89k]
  ------------------
 6390|  6.56k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  13.1k|#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: 957, False: 5.60k]
  |  |  ------------------
  ------------------
 6391|  6.56k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6392|  6.56k|		r = 0; /* do nothing, piv_match will take care of it */
 6393|  6.56k|		goto err;
 6394|  6.56k|	}
 6395|       |
 6396|  6.89k|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  381|  6.89k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6397|       |
 6398|       |	/* make sure our application is active */
 6399|       |
 6400|       |	/* first see if AID is active AID by reading discovery object '7E' */
 6401|       |	/* If not try selecting AID */
 6402|       |
 6403|       |	/* but if card does not support DISCOVERY object we can not use it */
 6404|  6.89k|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  582|  6.89k|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6404:6): [True: 3.35k, False: 3.54k]
  ------------------
 6405|  3.35k|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|  3.35k|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6406|  3.54k|	} else {
 6407|  3.54k|		r = piv_find_discovery(card);
 6408|       |#ifdef ENABLE_PIV_SM
 6409|       |		/*
 6410|       |		 * All 800-73-4 cards that support SM, also have a discovery object with
 6411|       |		 * the pin_policy, so can not have CI_DISCOVERY_USELESS
 6412|       |		 * Discovery object can be read with contact or contactless
 6413|       |		 * If read with SM and fails with 69 88  SC_ERROR_SM_INVALID_SESSION_KEY
 6414|       |		 * sm.c will close the SM connectrion, and set defer
 6415|       |		 */
 6416|       |		if (was_reset == 0 && (r == SC_ERROR_SM_INVALID_SESSION_KEY || priv->sm_flags & PIV_SM_FLAGS_DEFER_OPEN)) {
 6417|       |			sc_log(card->ctx, "SC_ERROR_SM_INVALID_SESSION_KEY || PIV_SM_FLAGS_DEFER_OPEN");
 6418|       |			piv_sm_open(card);
 6419|       |			r = piv_find_discovery(card);
 6420|       |		}
 6421|       |#endif /* ENABLE_PIV_SM */
 6422|  3.54k|	}
 6423|       |
 6424|  6.89k|	if (r < 0) {
  ------------------
  |  Branch (6424:6): [True: 6.87k, False: 20]
  ------------------
 6425|  6.87k|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  583|  6.87k|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6425:7): [True: 0, False: 6.87k]
  |  Branch (6425:24): [True: 6.57k, False: 302]
  ------------------
 6426|  6.57k|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6427|  6.57k|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  6.57k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6428|  6.57k|		} else {
 6429|    302|			r = 0; /* can't do anything with this card, hope there was no interference */
 6430|    302|		}
 6431|  6.87k|	}
 6432|       |
 6433|  6.89k|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6433:6): [True: 6.02k, False: 871]
  ------------------
 6434|  6.02k|		goto err;
 6435|       |
 6436|    871|	if (was_reset > 0)
  ------------------
  |  Branch (6436:6): [True: 0, False: 871]
  ------------------
 6437|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6438|       |
 6439|    871|	r = 0;
 6440|       |
 6441|  13.4k|err:
 6442|  13.4k|	if (priv)
  ------------------
  |  Branch (6442:6): [True: 7.85k, False: 5.60k]
  ------------------
 6443|  7.85k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  381|  7.85k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6444|  13.4k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  13.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  13.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  13.4k|	int _ret = r; \
  |  |  |  |  155|  13.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  13.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|  6.02k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.02k, False: 7.43k]
  |  |  |  |  ------------------
  |  |  |  |  157|  13.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  13.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|  13.4k|	return _ret; \
  |  |  |  |  163|  13.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6445|  13.4k|}

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

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

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

sc_get_setcos_driver:
 1130|  16.4k|{
 1131|  16.4k|	return sc_get_driver();
 1132|  16.4k|}
card-setcos.c:sc_get_driver:
 1110|  16.4k|{
 1111|  16.4k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1112|       |
 1113|  16.4k|	setcos_ops = *iso_drv->ops;
 1114|  16.4k|	setcos_ops.match_card = setcos_match_card;
 1115|  16.4k|	setcos_ops.init = setcos_init;
 1116|  16.4k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1116:6): [True: 1, False: 16.4k]
  ------------------
 1117|      1|		iso_ops = iso_drv->ops;
 1118|  16.4k|	setcos_ops.create_file = setcos_create_file;
 1119|  16.4k|	setcos_ops.set_security_env = setcos_set_security_env;
 1120|  16.4k|	setcos_ops.select_file = setcos_select_file;
 1121|  16.4k|	setcos_ops.list_files = setcos_list_files;
 1122|  16.4k|	setcos_ops.process_fci = setcos_process_fci;
 1123|  16.4k|	setcos_ops.construct_fci = setcos_construct_fci;
 1124|  16.4k|	setcos_ops.card_ctl = setcos_card_ctl;
 1125|       |
 1126|  16.4k|	return &setcos_drv;
 1127|  16.4k|}
card-setcos.c:setcos_match_card:
   83|  5.80k|{
   84|  5.80k|	sc_apdu_t apdu;
   85|  5.80k|	u8 buf[6];
   86|  5.80k|	int i;
   87|       |
   88|  5.80k|	i = _sc_match_atr(card, setcos_atrs, &card->type);
   89|  5.80k|	if (i < 0) {
  ------------------
  |  Branch (89:6): [True: 5.78k, False: 19]
  ------------------
   90|  5.78k|		if (match_hist_bytes(card, "FISE", 0)) {
  ------------------
  |  Branch (90:7): [True: 38, False: 5.74k]
  ------------------
   91|     38|			card->type = SC_CARD_TYPE_SETCOS_GENERIC;
   92|     38|			return 1;
   93|     38|		}
   94|       |		/* Check if it's a EID2.x applet by reading the version info */
   95|  5.74k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0xDF, 0x30);
  ------------------
  |  |  292|  5.74k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   96|  5.74k|		apdu.cla = 0x00;
   97|  5.74k|		apdu.resp = buf;
   98|  5.74k|		apdu.resplen = 5;
   99|  5.74k|		apdu.le = 5;
  100|  5.74k|		i = sc_transmit_apdu(card, &apdu);
  101|  5.74k|		if (i == 0 && apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && apdu.resplen == 5) {
  ------------------
  |  Branch (101:7): [True: 5.58k, False: 158]
  |  Branch (101:17): [True: 323, False: 5.26k]
  |  Branch (101:37): [True: 285, False: 38]
  |  Branch (101:57): [True: 240, False: 45]
  ------------------
  102|    240|			if (memcmp(buf, "v2.0", 4) == 0)
  ------------------
  |  Branch (102:8): [True: 116, False: 124]
  ------------------
  103|    116|				card->type = SC_CARD_TYPE_SETCOS_EID_V2_0;
  104|    124|			else if (memcmp(buf, "v2.1", 4) == 0)
  ------------------
  |  Branch (104:13): [True: 24, False: 100]
  ------------------
  105|     24|				card->type = SC_CARD_TYPE_SETCOS_EID_V2_1;
  106|    100|			else {
  107|    100|				buf[sizeof(buf) - 1] = '\0';
  108|    100|				sc_log(card->ctx,  "SetCOS EID applet %s is not supported", (char *) buf);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  109|    100|				return 0;
  110|    100|			}
  111|    140|			return 1;
  112|    240|		}
  113|       |
  114|  5.50k|		return 0;
  115|  5.74k|	}
  116|     19|	card->flags = setcos_atrs[i].flags;
  117|     19|	return 1;
  118|  5.80k|}
card-setcos.c:match_hist_bytes:
   64|  5.78k|{
   65|  5.78k|	const char *src = (const char *) card->reader->atr_info.hist_bytes;
   66|  5.78k|	size_t srclen = card->reader->atr_info.hist_bytes_len;
   67|  5.78k|	size_t offset = 0;
   68|       |
   69|  5.78k|	if (len == 0)
  ------------------
  |  Branch (69:6): [True: 5.78k, False: 0]
  ------------------
   70|  5.78k|		len = strlen(str);
   71|  5.78k|	if (srclen < len)
  ------------------
  |  Branch (71:6): [True: 3.59k, False: 2.18k]
  ------------------
   72|  3.59k|		return 0;
   73|  14.7k|	while (srclen - offset > len) {
  ------------------
  |  Branch (73:9): [True: 12.5k, False: 2.14k]
  ------------------
   74|  12.5k|		if (memcmp(src + offset, str, len) == 0) {
  ------------------
  |  Branch (74:7): [True: 38, False: 12.5k]
  ------------------
   75|     38|			return 1;
   76|     38|		}
   77|  12.5k|		offset++;
   78|  12.5k|	}
   79|  2.14k|	return 0;
   80|  2.18k|}
card-setcos.c:setcos_init:
  133|    197|{
  134|    197|	card->name = "SetCOS";
  135|       |
  136|       |	/* Handle unknown or forced cards */
  137|    197|	if (card->type < 0) {
  ------------------
  |  Branch (137:6): [True: 0, False: 197]
  ------------------
  138|      0|		card->type = SC_CARD_TYPE_SETCOS_GENERIC;
  139|      0|	}
  140|       |
  141|    197|	switch (card->type) {
  142|      6|	case SC_CARD_TYPE_SETCOS_NIDEL:
  ------------------
  |  Branch (142:2): [True: 6, False: 191]
  ------------------
  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|     12|	case SC_CARD_TYPE_SETCOS_44:
  ------------------
  |  Branch (148:2): [True: 12, False: 185]
  ------------------
  149|    128|	case SC_CARD_TYPE_SETCOS_EID_V2_0:
  ------------------
  |  Branch (149:2): [True: 116, False: 81]
  ------------------
  150|    152|	case SC_CARD_TYPE_SETCOS_EID_V2_1:
  ------------------
  |  Branch (150:2): [True: 24, False: 173]
  ------------------
  151|    152|		card->cla = 0x00;
  152|    152|		card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  564|    152|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  153|    152|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    152|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  154|    152|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|    152|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  155|    152|		break;
  156|     39|	default:
  ------------------
  |  Branch (156:2): [True: 39, False: 158]
  ------------------
  157|       |		/* XXX: Get SetCOS version */
  158|     39|		card->cla = 0x80;	/* SetCOS 4.3.x */
  159|       |		/* State that we have an RNG */
  160|     39|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|     39|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  161|     39|		break;
  162|    197|	}
  163|       |
  164|    197|	switch (card->type) {
  ------------------
  |  Branch (164:10): [True: 159, False: 38]
  ------------------
  165|      1|	case SC_CARD_TYPE_SETCOS_PKI: {
  ------------------
  |  Branch (165:2): [True: 1, False: 196]
  ------------------
  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|     12|	case SC_CARD_TYPE_SETCOS_44:
  ------------------
  |  Branch (174:2): [True: 12, False: 185]
  ------------------
  175|     18|	case SC_CARD_TYPE_SETCOS_NIDEL:
  ------------------
  |  Branch (175:2): [True: 6, False: 191]
  ------------------
  176|    134|	case SC_CARD_TYPE_SETCOS_EID_V2_0:
  ------------------
  |  Branch (176:2): [True: 116, False: 81]
  ------------------
  177|    158|	case SC_CARD_TYPE_SETCOS_EID_V2_1:
  ------------------
  |  Branch (177:2): [True: 24, False: 173]
  ------------------
  178|    158|		{
  179|    158|			unsigned long flags;
  180|       |
  181|    158|			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    158|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|    158|#define SC_ALGORITHM_RSA_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|    158|#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|    158|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  182|    158|			flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  142|    158|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              			flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  143|    158|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  183|    158|			flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    158|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  184|       |
  185|    158|			_sc_card_add_rsa_alg(card, 512, flags, 0);
  186|    158|			_sc_card_add_rsa_alg(card, 768, flags, 0);
  187|    158|			_sc_card_add_rsa_alg(card, 1024, flags, 0);
  188|    158|			_sc_card_add_rsa_alg(card, 2048, flags, 0);
  189|    158|		}
  190|    158|		break;
  191|    197|	}
  192|    197|	return 0;
  193|    197|}
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|    986|{
  896|    986|	int r;
  897|       |
  898|    986|	r = iso_ops->select_file(card, in_path, file);
  899|    986|	if (r)
  ------------------
  |  Branch (899:6): [True: 713, False: 273]
  ------------------
  900|    713|		return r;
  901|    273|	if (file != NULL) {
  ------------------
  |  Branch (901:6): [True: 225, False: 48]
  ------------------
  902|    225|		if (card->type == SC_CARD_TYPE_SETCOS_44 ||
  ------------------
  |  Branch (902:7): [True: 26, False: 199]
  ------------------
  903|    199|		    card->type == SC_CARD_TYPE_SETCOS_NIDEL ||
  ------------------
  |  Branch (903:7): [True: 7, False: 192]
  ------------------
  904|    192|		    SETCOS_IS_EID_APPLET(card))
  ------------------
  |  |   46|    192|#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: 121, False: 71]
  |  |  |  Branch (46:85): [True: 25, False: 46]
  |  |  ------------------
  ------------------
  905|    179|			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|    225|	}
  909|    273|	return 0;
  910|    986|}
card-setcos.c:parse_sec_attr_44:
  740|    179|{
  741|       |	/* OpenSc Operation values for each command operation-type */
  742|    179|	const int df_idx[8] = {	 /* byte 1 = OpenSC type of AC Bit0,  byte 2 = OpenSC type of AC Bit1 ...*/
  743|    179|		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  168|    179|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  169|    179|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  169|    179|#define SC_AC_OP_CREATE			3
  ------------------
  744|    179|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    179|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    179|#define SC_AC_OP_REHABILITATE		4
  ------------------
  745|    179|		SC_AC_OP_LOCK, SC_AC_OP_DELETE, -1};
  ------------------
  |  |  167|    179|#define SC_AC_OP_LOCK			1
  ------------------
              		SC_AC_OP_LOCK, SC_AC_OP_DELETE, -1};
  ------------------
  |  |  168|    179|#define SC_AC_OP_DELETE			2
  ------------------
  746|    179|	const int ef_idx[8] = {
  747|    179|		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  188|    179|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  189|    179|#define SC_AC_OP_UPDATE			23
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  190|    179|#define SC_AC_OP_WRITE			24
  ------------------
  748|    179|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    179|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    179|#define SC_AC_OP_REHABILITATE		4
  ------------------
  749|    179|		-1, SC_AC_OP_ERASE, -1};
  ------------------
  |  |  202|    179|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    179|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  750|    179|	const int efi_idx[8] = { /* internal EF used for RSA keys */
  751|    179|		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  188|    179|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  202|    179|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    179|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  189|    179|#define SC_AC_OP_UPDATE			23
  ------------------
  752|    179|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    179|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    179|#define SC_AC_OP_REHABILITATE		4
  ------------------
  753|    179|		-1, SC_AC_OP_ERASE, -1};
  ------------------
  |  |  202|    179|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    179|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  754|       |
  755|    179|	u8		bValue;
  756|    179|	int		i;
  757|    179|	int		iKeyRef = 0;
  758|    179|	int		iMethod;
  759|    179|	int		iPinCount;
  760|    179|	int		iOffset = 0;
  761|    179|	int		iOperation;
  762|    179|	const int*	p_idx;
  763|       |
  764|       |	/* Check all sub-AC definitions within the total AC */
  765|  1.12k|	while (len > 1 && (size_t)iOffset < len) {	/* minimum length = 2 */
  ------------------
  |  Branch (765:9): [True: 1.04k, False: 77]
  |  Branch (765:20): [True: 966, False: 79]
  ------------------
  766|    966|		size_t iACLen   = buf[iOffset] & 0x0F;
  767|    966|		if (iACLen >= len)
  ------------------
  |  Branch (767:7): [True: 17, False: 949]
  ------------------
  768|     17|			break;
  769|       |
  770|    949|		iMethod = SC_AC_NONE;		/* default no authentication required */
  ------------------
  |  |  150|    949|#define SC_AC_NONE			0x00000000
  ------------------
  771|       |
  772|    949|		if (buf[iOffset] & 0X80) { /* AC in adaptive coding */
  ------------------
  |  Branch (772:7): [True: 369, False: 580]
  ------------------
  773|       |			/* Evaluates only the command-byte, not the optional P1/P2/Option bytes */
  774|    369|			size_t	iParmLen = 1;			/* command-byte is always present */
  775|    369|			size_t	iKeyLen  = 0;			/* Encryption key is optional */
  776|       |
  777|    369|			if (buf[iOffset]   & 0x20) iKeyLen++;
  ------------------
  |  Branch (777:8): [True: 223, False: 146]
  ------------------
  778|    369|			if (buf[iOffset+1] & 0x40) iParmLen++;
  ------------------
  |  Branch (778:8): [True: 145, False: 224]
  ------------------
  779|    369|			if (buf[iOffset+1] & 0x20) iParmLen++;
  ------------------
  |  Branch (779:8): [True: 185, False: 184]
  ------------------
  780|    369|			if (buf[iOffset+1] & 0x10) iParmLen++;
  ------------------
  |  Branch (780:8): [True: 172, False: 197]
  ------------------
  781|    369|			if (buf[iOffset+1] & 0x08) iParmLen++;
  ------------------
  |  Branch (781:8): [True: 42, False: 327]
  ------------------
  782|       |
  783|       |			/* Get KeyNumber if available */
  784|    369|			if(iKeyLen) {
  ------------------
  |  Branch (784:7): [True: 223, False: 146]
  ------------------
  785|    223|				int iSC;
  786|    223|				if (len < 1 + iACLen)
  ------------------
  |  Branch (786:9): [True: 0, False: 223]
  ------------------
  787|      0|					break;
  788|    223|				iSC = buf[iOffset+iACLen];
  789|       |
  790|    223|				switch( (iSC>>5) & 0x03 ){
  ------------------
  |  Branch (790:13): [True: 223, False: 0]
  ------------------
  791|     23|				case 0:
  ------------------
  |  Branch (791:5): [True: 23, False: 200]
  ------------------
  792|     23|					iMethod = SC_AC_TERM;		/* key authentication */
  ------------------
  |  |  152|     23|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  793|     23|					break;
  794|     98|				case 1:
  ------------------
  |  Branch (794:5): [True: 98, False: 125]
  ------------------
  795|     98|					iMethod = SC_AC_AUT;		/* key authentication  */
  ------------------
  |  |  154|     98|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  796|     98|					break;
  797|     23|				case 2:
  ------------------
  |  Branch (797:5): [True: 23, False: 200]
  ------------------
  798|    102|				case 3:
  ------------------
  |  Branch (798:5): [True: 79, False: 144]
  ------------------
  799|    102|					iMethod = SC_AC_PRO;		/* secure messaging */
  ------------------
  |  |  153|    102|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  800|    102|					break;
  801|    223|				}
  802|    223|				iKeyRef = iSC & 0x1F;			/* get key number */
  803|    223|			}
  804|       |
  805|       |			/* Get PinNumber if available */
  806|    369|			if (iACLen > (1+iParmLen+iKeyLen)) {  /* check via total length if pin is present */
  ------------------
  |  Branch (806:8): [True: 32, False: 337]
  ------------------
  807|     32|				if (len < 1+1+1+(size_t)iParmLen)
  ------------------
  |  Branch (807:9): [True: 0, False: 32]
  ------------------
  808|      0|					break;
  809|     32|				iKeyRef = buf[iOffset+1+1+iParmLen];  /* PTL + AM-header + parameter-bytes */
  810|     32|				iMethod = SC_AC_CHV;
  ------------------
  |  |  151|     32|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  811|     32|			}
  812|       |
  813|       |			/* Convert SETCOS command to OpenSC command group */
  814|    369|			if (len < 1+2)
  ------------------
  |  Branch (814:8): [True: 6, False: 363]
  ------------------
  815|      6|				break;
  816|    363|			switch(buf[iOffset+2]){
  817|     11|			case 0x2A:			/* crypto operation */
  ------------------
  |  Branch (817:4): [True: 11, False: 352]
  ------------------
  818|     11|				iOperation = SC_AC_OP_CRYPTO;
  ------------------
  |  |  173|     11|#define SC_AC_OP_CRYPTO			7
  ------------------
  819|     11|				break;
  820|     19|			case 0x46:			/* key-generation operation */
  ------------------
  |  Branch (820:4): [True: 19, False: 344]
  ------------------
  821|     19|				iOperation = SC_AC_OP_UPDATE;
  ------------------
  |  |  189|     19|#define SC_AC_OP_UPDATE			23
  ------------------
  822|     19|				break;
  823|    333|			default:
  ------------------
  |  Branch (823:4): [True: 333, False: 30]
  ------------------
  824|    333|				iOperation = SC_AC_OP_SELECT;
  ------------------
  |  |  166|    333|#define SC_AC_OP_SELECT			0
  ------------------
  825|    333|				break;
  826|    363|			}
  827|    363|			sc_file_add_acl_entry(file, iOperation, iMethod, iKeyRef);
  828|    363|		}
  829|    580|		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|    580|			switch (file->type) {
  834|     75|			case SC_FILE_TYPE_DF:            /* DF */
  ------------------
  |  |  214|     75|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (834:4): [True: 75, False: 505]
  ------------------
  835|     75|				p_idx = df_idx;
  836|     75|				break;
  837|     76|			case SC_FILE_TYPE_INTERNAL_EF:   /* EF for RSA keys */
  ------------------
  |  |  215|     76|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (837:4): [True: 76, False: 504]
  ------------------
  838|     76|				p_idx = efi_idx;
  839|     76|				break;
  840|    429|			default:                         /* EF */
  ------------------
  |  Branch (840:4): [True: 429, False: 151]
  ------------------
  841|    429|				p_idx = ef_idx;
  842|    429|				break;
  843|    580|			}
  844|       |
  845|       |			/* Encryption key present ? */
  846|    580|			iPinCount = iACLen > 0 ? (int)iACLen - 1 : 0;
  ------------------
  |  Branch (846:16): [True: 151, False: 429]
  ------------------
  847|       |
  848|    580|			if (buf[iOffset] & 0x20) {
  ------------------
  |  Branch (848:8): [True: 284, False: 296]
  ------------------
  849|    284|				int iSC;
  850|    284|				if (len < 1 + (size_t)iACLen)
  ------------------
  |  Branch (850:9): [True: 0, False: 284]
  ------------------
  851|      0|					break;
  852|    284|				iSC = buf[iOffset + iACLen];
  853|       |
  854|    284|				switch( (iSC>>5) & 0x03 ) {
  ------------------
  |  Branch (854:13): [True: 284, False: 0]
  ------------------
  855|     26|				case 0:
  ------------------
  |  Branch (855:5): [True: 26, False: 258]
  ------------------
  856|     26|					iMethod = SC_AC_TERM;		/* key authentication */
  ------------------
  |  |  152|     26|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  857|     26|					break;
  858|    133|				case 1:
  ------------------
  |  Branch (858:5): [True: 133, False: 151]
  ------------------
  859|    133|					iMethod = SC_AC_AUT;		/* key authentication  */
  ------------------
  |  |  154|    133|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  860|    133|					break;
  861|     13|				case 2:
  ------------------
  |  Branch (861:5): [True: 13, False: 271]
  ------------------
  862|    125|				case 3:
  ------------------
  |  Branch (862:5): [True: 112, False: 172]
  ------------------
  863|    125|					iMethod = SC_AC_PRO;		/* secure messaging */
  ------------------
  |  |  153|    125|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  864|    125|					break;
  865|    284|				}
  866|    284|				iKeyRef = iSC & 0x1F;			/* get key number */
  867|       |
  868|    284|				iPinCount--;				/* one byte used for keyReference  */
  869|    284|			}
  870|       |
  871|       |			/* Pin present ? */
  872|    580|			if ( iPinCount > 0 ) {
  ------------------
  |  Branch (872:9): [True: 81, False: 499]
  ------------------
  873|     81|				if (len < 1 + 2)
  ------------------
  |  Branch (873:9): [True: 0, False: 81]
  ------------------
  874|      0|					break;
  875|     81|				iKeyRef = buf[iOffset + 2];	/* pin ref */
  876|     81|				iMethod = SC_AC_CHV;
  ------------------
  |  |  151|     81|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  877|     81|			}
  878|       |
  879|       |			/* Add AC for each command-operationType into OpenSc structure */
  880|    580|			bValue = buf[iOffset + 1];
  881|  5.22k|			for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (881:16): [True: 4.64k, False: 580]
  ------------------
  882|  4.64k|				if((bValue & 1) && (p_idx[i] >= 0))
  ------------------
  |  Branch (882:8): [True: 991, False: 3.64k]
  |  Branch (882:24): [True: 659, False: 332]
  ------------------
  883|    659|					sc_file_add_acl_entry(file, p_idx[i], iMethod, iKeyRef);
  884|  4.64k|				bValue >>= 1;
  885|  4.64k|			}
  886|    580|		}
  887|       |		/* Current field treated, get next AC sub-field */
  888|    943|		iOffset += iACLen +1;		/* AC + PTL-byte */
  889|    943|		len     -= iACLen +1;
  890|    943|	}
  891|    179|}
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: 15, False: 31]
  ------------------
  717|     15|		return;
  718|     31|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|     31|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (718:6): [True: 4, False: 27]
  ------------------
  719|      4|		const int df_idx[6] = {
  720|      4|			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  166|      4|#define SC_AC_OP_SELECT			0
  ------------------
              			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  167|      4|#define SC_AC_OP_LOCK			1
  ------------------
              			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  168|      4|#define SC_AC_OP_DELETE			2
  ------------------
  721|      4|			SC_AC_OP_CREATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  169|      4|#define SC_AC_OP_CREATE			3
  ------------------
              			SC_AC_OP_CREATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|      4|#define SC_AC_OP_REHABILITATE		4
  ------------------
  722|      4|			SC_AC_OP_INVALIDATE
  ------------------
  |  |  171|      4|#define SC_AC_OP_INVALIDATE		5
  ------------------
  723|      4|		};
  724|     28|		for (i = 0; i < 6; i++)
  ------------------
  |  Branch (724:15): [True: 24, False: 4]
  ------------------
  725|     24|			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|    217|	for (i = 0; i < 6; i++)
  ------------------
  |  Branch (735:14): [True: 186, False: 31]
  ------------------
  736|    186|		add_acl_entry(file, idx[i], buf[i]);
  737|     31|}
card-setcos.c:add_acl_entry:
  683|    186|{
  684|    186|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    186|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  685|       |
  686|    186|	switch (byte >> 4) {
  687|     28|	case 0:
  ------------------
  |  Branch (687:2): [True: 28, False: 158]
  ------------------
  688|     28|		method = SC_AC_NONE;
  ------------------
  |  |  150|     28|#define SC_AC_NONE			0x00000000
  ------------------
  689|     28|		break;
  690|     13|	case 1:
  ------------------
  |  Branch (690:2): [True: 13, False: 173]
  ------------------
  691|     13|		method = SC_AC_CHV;
  ------------------
  |  |  151|     13|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  692|     13|		key_ref = 1;
  693|     13|		break;
  694|     25|	case 2:
  ------------------
  |  Branch (694:2): [True: 25, False: 161]
  ------------------
  695|     25|		method = SC_AC_CHV;
  ------------------
  |  |  151|     25|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  696|     25|		key_ref = 2;
  697|     25|		break;
  698|     21|	case 4:
  ------------------
  |  Branch (698:2): [True: 21, False: 165]
  ------------------
  699|     21|		method = SC_AC_TERM;
  ------------------
  |  |  152|     21|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  700|     21|		break;
  701|     41|	case 15:
  ------------------
  |  Branch (701:2): [True: 41, False: 145]
  ------------------
  702|     41|		method = SC_AC_NEVER;
  ------------------
  |  |  163|     41|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  703|     41|		break;
  704|     58|	default:
  ------------------
  |  Branch (704:2): [True: 58, False: 128]
  ------------------
  705|     58|		method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     58|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  706|     58|		break;
  707|    186|	}
  708|    186|	sc_file_add_acl_entry(file, op, method, key_ref);
  709|    186|}
card-setcos.c:setcos_process_fci:
  936|    220|{
  937|    220|	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|    220|	if (r >= 0 && (card->type == SC_CARD_TYPE_SETCOS_44 ||
  ------------------
  |  Branch (941:6): [True: 220, False: 0]
  |  Branch (941:17): [True: 25, False: 195]
  ------------------
  942|    195|	               SETCOS_IS_EID_APPLET(card))) {
  ------------------
  |  |   46|    195|#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: 119, False: 76]
  |  |  |  Branch (46:85): [True: 25, False: 51]
  |  |  ------------------
  ------------------
  943|    169|		const u8 *tag;
  944|    169|		size_t taglen = 1;
  945|    169|		tag = (u8 *) sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &taglen);
  946|    169|		if (tag != NULL && taglen == 1 && *tag == 0x11)
  ------------------
  |  Branch (946:7): [True: 44, False: 125]
  |  Branch (946:22): [True: 36, False: 8]
  |  Branch (946:37): [True: 4, False: 32]
  ------------------
  947|      4|			file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|      4|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  948|    169|	}
  949|       |
  950|    220|	return r;
  951|    220|}
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: 2, False: 2]
  |  |  ------------------
  ------------------
  |  Branch (1087:6): [True: 5, False: 1]
  ------------------
 1088|      2|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      2|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1089|       |
 1090|      4|	switch(cmd) {
  ------------------
  |  Branch (1090:9): [True: 0, False: 4]
  ------------------
 1091|      0|	case SC_CARDCTL_SETCOS_PUTDATA:
  ------------------
  |  Branch (1091:2): [True: 0, False: 4]
  ------------------
 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: 4]
  ------------------
 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: 4]
  ------------------
 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: 4]
  ------------------
 1103|      0|		return setcos_activate_file(card);
 1104|      4|	}
 1105|       |
 1106|      4|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      4|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1107|      4|}

sc_get_skeid_driver:
  179|  16.4k|{
  180|  16.4k|	if (iso_ops == NULL) iso_ops = sc_get_iso7816_driver()->ops;
  ------------------
  |  Branch (180:6): [True: 1, False: 16.4k]
  ------------------
  181|  16.4k|	skeid_ops = *iso_ops;
  182|  16.4k|	skeid_ops.match_card = skeid_match_card;
  183|  16.4k|	skeid_ops.init = skeid_init;
  184|  16.4k|	skeid_ops.set_security_env = skeid_set_security_env;
  185|  16.4k|	skeid_ops.logout = skeid_logout;
  186|  16.4k|	return &skeid_drv;
  187|  16.4k|}
card-skeid.c:skeid_match_card:
   73|  15.4k|{
   74|  15.4k|	if (_sc_match_atr(card, skeid_atrs, &card->type) < 0 || skeid_known_url(card) != SC_SUCCESS)
  ------------------
  |  |   28|    107|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 15.3k, False: 107]
  |  Branch (74:58): [True: 82, False: 25]
  ------------------
   75|  15.4k|		return 0;
   76|       |
   77|     25|	sc_log(card->ctx,  "Slovak eID card v3 (CardOS 5.4)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   78|       |
   79|     25|	return 1;
   80|  15.4k|}
card-skeid.c:skeid_known_url:
   53|    107|{
   54|    107|	const struct sc_aid skeid_aid_eid = {{0xE8, 0x07, 0x04, 0x00, 0x7F, 0x00, 0x07, 0x03, 0x02}, 9};
   55|    107|	const char *known_url = "\x80\x01\x00\x5F\x50\x28http://www.minv.sk/cif/cif-sk-eid-v3.xml";
   56|    107|	u8 buf[SKEID_KNOWN_URL_LEN];
   57|       |
   58|    107|	sc_path_t url_path;
   59|       |
   60|    107|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    107|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   61|       |
   62|    107|	sc_path_set(&url_path, SC_PATH_TYPE_DF_NAME, skeid_aid_eid.value, skeid_aid_eid.len, 0, 0);
  ------------------
  |  |  118|    107|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   63|       |
   64|    107|	if (sc_select_file(card, &url_path, NULL) == SC_SUCCESS
  ------------------
  |  |   28|    214|#define SC_SUCCESS				0
  ------------------
  |  Branch (64:6): [True: 58, False: 49]
  ------------------
   65|     58|		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|     58|#define SKEID_KNOWN_URL_LEN 46
  ------------------
              		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|    165|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (65:6): [True: 40, False: 18]
  ------------------
   66|     40|		&& !memcmp(buf, known_url, SKEID_KNOWN_URL_LEN))
  ------------------
  |  |   30|     40|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (66:6): [True: 25, False: 15]
  ------------------
   67|     25|		r = SC_SUCCESS;
  ------------------
  |  |   28|     25|#define SC_SUCCESS				0
  ------------------
   68|       |
   69|    107|	return r;
   70|    107|}
card-skeid.c:skeid_init:
  108|     25|{
  109|     25|	const unsigned long flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  120|     25|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|     25|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|     25|#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|     25|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  110|     25|	const size_t data_field_length = 437;
  111|     25|	int r;
  112|       |
  113|     25|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     25|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     25|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     25|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 25]
  |  |  ------------------
  ------------------
  114|       |
  115|     25|	card->name = "Slovak eID (CardOS)";
  116|     25|	card->type = SC_CARD_TYPE_SKEID_V3;
  117|     25|	card->cla = 0x00;
  118|       |
  119|     25|	r = skeid_get_serialnr(card);
  120|     25|	LOG_TEST_RET(card->ctx, r, "Error reading serial number.");
  ------------------
  |  |  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: 9, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  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|     25|} 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|     25|{
   84|     25|	int r;
   85|     25|	sc_apdu_t apdu;
   86|     25|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
   87|       |
   88|     25|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x81);
  ------------------
  |  |  292|     25|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   89|     25|	apdu.resp = rbuf;
   90|     25|	apdu.resplen = sizeof(rbuf);
   91|     25|	apdu.le = 256;
   92|     25|	r = sc_transmit_apdu(card, &apdu);
   93|     25|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     25|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     25|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     25|	int _ret = (r); \
  |  |  |  |  168|     25|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  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|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   94|     24|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (94:6): [True: 3, False: 21]
  |  Branch (94:26): [True: 1, False: 20]
  ------------------
   95|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
   96|     20|	if (apdu.resplen == 8) {
  ------------------
  |  Branch (96:6): [True: 16, False: 4]
  ------------------
   97|       |		/* cache serial number */
   98|     16|		memcpy(card->serialnr.value, rbuf, 8);
   99|     16|		card->serialnr.len = 8;
  100|     16|	} else {
  101|      4|		sc_log(card->ctx, "unexpected response to GET DATA serial number");
  ------------------
  |  |   71|      4|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  102|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
  103|      4|	}
  104|     16|	return SC_SUCCESS;
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
  105|     20|}
card-skeid.c:skeid_set_security_env:
  146|     40|{
  147|     40|	int key_id;
  148|     40|	int r;
  149|       |
  150|     40|	if (card == NULL || env == NULL)
  ------------------
  |  Branch (150:6): [True: 0, False: 40]
  |  Branch (150:22): [True: 0, False: 40]
  ------------------
  151|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  152|       |
  153|     40|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || env->key_ref_len != 1) {
  ------------------
  |  |   67|     40|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (153:6): [True: 0, False: 40]
  |  Branch (153:52): [True: 0, False: 40]
  ------------------
  154|      0|		sc_log(card->ctx, "No or invalid key reference");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  155|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  156|      0|	}
  157|       |
  158|       |	/* here we follow the behaviour of the proprietary driver accompanying the card
  159|       |	 * where security operations are preceded by MSE RESTORE rather than MSE SET
  160|       |	 */
  161|     40|	key_id = env->key_ref[0];
  162|     40|	r = sc_restore_security_env(card, key_id);
  163|       |
  164|     40|	return r;
  165|     40|}

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

sc_get_starcos_driver:
 2118|  16.4k|{
 2119|  16.4k|	return sc_get_driver();
 2120|  16.4k|}
card-starcos.c:sc_get_driver:
 2093|  16.4k|{
 2094|  16.4k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2095|  16.4k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2095:6): [True: 1, False: 16.4k]
  ------------------
 2096|      1|		iso_ops = iso_drv->ops;
 2097|       |
 2098|  16.4k|	starcos_ops = *iso_drv->ops;
 2099|  16.4k|	starcos_ops.match_card = starcos_match_card;
 2100|  16.4k|	starcos_ops.init   = starcos_init;
 2101|  16.4k|	starcos_ops.finish = starcos_finish;
 2102|  16.4k|	starcos_ops.select_file = starcos_select_file;
 2103|  16.4k|	starcos_ops.get_challenge = starcos_get_challenge;
 2104|  16.4k|	starcos_ops.check_sw    = starcos_check_sw;
 2105|  16.4k|	starcos_ops.create_file = starcos_create_file;
 2106|  16.4k|	starcos_ops.delete_file = NULL;
 2107|  16.4k|	starcos_ops.set_security_env  = starcos_set_security_env;
 2108|  16.4k|	starcos_ops.compute_signature = starcos_compute_signature;
 2109|  16.4k|	starcos_ops.decipher = starcos_decipher;
 2110|  16.4k|	starcos_ops.card_ctl    = starcos_card_ctl;
 2111|  16.4k|	starcos_ops.logout      = starcos_logout;
 2112|  16.4k|	starcos_ops.pin_cmd     = starcos_pin_cmd;
 2113|       |
 2114|  16.4k|	return &starcos_drv;
 2115|  16.4k|}
card-starcos.c:starcos_match_card:
  125|  14.0k|{
  126|  14.0k|	int i;
  127|       |
  128|  14.0k|	i = _sc_match_atr(card, starcos_atrs, &card->type);
  129|  14.0k|	if (i < 0)
  ------------------
  |  Branch (129:6): [True: 13.1k, False: 912]
  ------------------
  130|  13.1k|		return 0;
  131|    912|	return 1;
  132|  14.0k|}
card-starcos.c:starcos_init:
  359|    912|{
  360|    912|	unsigned int flags;
  361|    912|	starcos_ex_data *ex_data;
  362|       |
  363|    912|	ex_data = calloc(1, sizeof(starcos_ex_data));
  364|    912|	if (ex_data == NULL)
  ------------------
  |  Branch (364:6): [True: 0, False: 912]
  ------------------
  365|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  366|       |
  367|    912|	card->name = "STARCOS";
  368|    912|	card->cla  = 0x00;
  369|    912|	card->drv_data = (void *)ex_data;
  370|    912|	ex_data->pin_encoding = PIN_ENCODING_DETERMINE;
  ------------------
  |  |   96|    912|#define PIN_ENCODING_DETERMINE	0
  ------------------
  371|       |
  372|    912|	flags = SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  120|    912|#define SC_ALGORITHM_RSA_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|    912|#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|    912|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  373|    912|		| SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|    912|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  374|    912|		| SC_ALGORITHM_RSA_PAD_ISO9796
  ------------------
  |  |  115|    912|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  375|    912|		| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  142|    912|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  376|    912|		| SC_ALGORITHM_RSA_HASH_SHA1
  ------------------
  |  |  143|    912|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  377|    912|		| SC_ALGORITHM_RSA_HASH_MD5
  ------------------
  |  |  144|    912|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  378|    912|		| SC_ALGORITHM_RSA_HASH_RIPEMD160
  ------------------
  |  |  146|    912|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  379|    912|		| SC_ALGORITHM_RSA_HASH_MD5_SHA1;
  ------------------
  |  |  145|    912|#define SC_ALGORITHM_RSA_HASH_MD5_SHA1	0x00000800
  ------------------
  380|       |
  381|    912|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    912|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  382|       |
  383|    912|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  1.82k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    912|#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: 598, False: 314]
  |  |  |  |  |  Branch (119:65): [True: 0, False: 314]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|    314|#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: 99, False: 215]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 215]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|       |
  385|    697|		flags |= SC_CARD_FLAG_RNG
  ------------------
  |  |  543|    697|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  386|    697|			| SC_ALGORITHM_RSA_HASH_SHA224
  ------------------
  |  |  150|    697|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
  387|    697|			| SC_ALGORITHM_RSA_HASH_SHA256
  ------------------
  |  |  147|    697|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  388|    697|			| SC_ALGORITHM_RSA_HASH_SHA384
  ------------------
  |  |  148|    697|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  389|    697|			| SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  149|    697|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  390|    697|			| SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  116|    697|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  391|       |
  392|    697|		_sc_card_add_rsa_alg(card, 512, flags, 0x10001);
  393|    697|		_sc_card_add_rsa_alg(card, 768, flags, 0x10001);
  394|    697|		_sc_card_add_rsa_alg(card,1024, flags, 0x10001);
  395|    697|		_sc_card_add_rsa_alg(card,1728, flags, 0x10001);
  396|    697|		_sc_card_add_rsa_alg(card,1976, flags, 0x10001);
  397|    697|		_sc_card_add_rsa_alg(card,2048, flags, 0x10001);
  398|    697|		if ( IS_V34(card) ) {
  ------------------
  |  |  119|    697|#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: 598, False: 99]
  |  |  |  Branch (119:65): [True: 0, False: 99]
  |  |  ------------------
  ------------------
  399|    598|			card->name = "STARCOS 3.4";
  400|    598|			card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    598|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  401|    598|		} else {
  402|     99|			card->name = "STARCOS 3.5";
  403|     99|			_sc_card_add_rsa_alg(card,3072, flags, 0x10001);
  404|     99|		}
  405|    697|		card->max_send_size = 255;
  406|    697|		card->max_recv_size = 256;
  407|    697|	} else {
  408|    215|		_sc_card_add_rsa_alg(card, 512, flags, 0x10001);
  409|    215|		_sc_card_add_rsa_alg(card, 768, flags, 0x10001);
  410|    215|		_sc_card_add_rsa_alg(card,1024, flags, 0x10001);
  411|       |
  412|       |		/* we need read_binary&friends with max 128 bytes per read */
  413|    215|		card->max_send_size = 128;
  414|    215|		card->max_recv_size = 128;
  415|    215|	}
  416|       |
  417|    912|	if (sc_parse_ef_atr(card) == SC_SUCCESS) {
  ------------------
  |  |   28|    912|#define SC_SUCCESS				0
  ------------------
  |  Branch (417:6): [True: 141, False: 771]
  ------------------
  418|    141|		size_t max_recv_size = 0;
  419|    141|		size_t max_send_size = 0;
  420|       |
  421|       |		/* Add max. length values from IAS/ECC specific issuer data */
  422|    141|		if ( card->ef_atr->issuer_data_len >= 4 ) {
  ------------------
  |  Branch (422:8): [True: 88, False: 53]
  ------------------
  423|     88|			max_recv_size = bebytes2ushort(card->ef_atr->issuer_data);
  424|     88|			max_send_size = bebytes2ushort(card->ef_atr->issuer_data + 2);
  425|     88|		}
  426|       |		/* which could be overridden with ISO7816 EF.ATR options, if present */
  427|    141|		if (card->ef_atr->max_response_apdu > 0) {
  ------------------
  |  Branch (427:7): [True: 0, False: 141]
  ------------------
  428|      0|			max_recv_size = card->ef_atr->max_response_apdu;
  429|      0|		}
  430|    141|		if (card->ef_atr->max_command_apdu > 0) {
  ------------------
  |  Branch (430:7): [True: 0, False: 141]
  ------------------
  431|      0|			max_send_size = card->ef_atr->max_command_apdu;
  432|      0|		}
  433|       |
  434|    141|		if ( max_send_size > 256 && max_recv_size > 256 ) {
  ------------------
  |  Branch (434:8): [True: 87, False: 54]
  |  Branch (434:31): [True: 78, False: 9]
  ------------------
  435|     78|			size_t max_recv_size_prev = card->max_recv_size;
  436|     78|			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|     78|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|     78|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  439|       |			/* the received data should not exceed max_recv_size including the sw1/sw2 */
  440|     78|			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|     78|			card->max_send_size = max_send_size - 10;
  443|       |			/* probe reader for extended APDU support */
  444|     78|			if ( starcos_probe_reader_for_ext_apdu(card) ) {
  ------------------
  |  Branch (444:9): [True: 58, False: 20]
  ------------------
  445|     58|				sc_log(card->ctx, "Successfully probed extended APDU, enabling extended APDU with max send/recv %d/%d",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  446|     58|					(int)card->max_send_size, (int)card->max_recv_size);
  447|     58|			} else {
  448|     20|				card->caps &= ~(SC_CARD_CAP_APDU_EXT);
  ------------------
  |  |  554|     20|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  449|     20|				card->max_recv_size = max_recv_size_prev;
  450|     20|				card->max_send_size = max_send_size_prev;
  451|     20|				sc_log(card->ctx, "Ext APDU probing failed, the actual reader does not support ext APDU");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  452|     20|			}
  453|     78|		}
  454|    141|	}
  455|       |
  456|    912|	if ( ex_data->pin_encoding == PIN_ENCODING_DETERMINE ) {
  ------------------
  |  |   96|    912|#define PIN_ENCODING_DETERMINE	0
  ------------------
  |  Branch (456:7): [True: 912, False: 0]
  ------------------
  457|       |		// about to determine PIN encoding
  458|    912|		ex_data->pin_encoding = starcos_determine_pin_encoding(card);
  459|    912|	}
  460|       |
  461|    912|	if ( card->type == SC_CARD_TYPE_STARCOS_V3_4 && starcos_has_esign_app(card) ) {
  ------------------
  |  Branch (461:7): [True: 598, False: 314]
  |  Branch (461:50): [True: 177, False: 421]
  ------------------
  462|    177|		card->type = SC_CARD_TYPE_STARCOS_V3_4_ESIGN;
  463|    177|		sc_log(card->ctx, "Card has eSign app, card type changed to %d", card->type);
  ------------------
  |  |   71|    177|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  464|    177|	}
  465|       |
  466|    912|	return 0;
  467|    912|}
card-starcos.c:starcos_probe_reader_for_ext_apdu:
  301|     78|static int starcos_probe_reader_for_ext_apdu(sc_card_t * card) {
  302|     78|	sc_apdu_t apdu;
  303|     78|	int rv;
  304|       |	/* try to read STARCOS3X_PROBE_APDU_LENGTH bytes */
  305|     78|	u8 data[STARCOS3X_PROBE_APDU_LENGTH];
  306|       |
  307|       |	/* Get Data: Get Chip Serial Number */
  308|     78|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_EXT, 0xCA, 0x9F, 0x6C);
  ------------------
  |  |  297|     78|#define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  292|     78|#define SC_APDU_CASE_2_SHORT		0x02
  |  |  ------------------
  |  |               #define SC_APDU_CASE_2_EXT		SC_APDU_CASE_2_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|     78|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
  309|     78|	apdu.cla = 0xA0;
  310|     78|	apdu.resp = data;
  311|     78|	apdu.resplen = sizeof(data);
  312|     78|	apdu.le = apdu.resplen;
  313|     78|	rv = sc_transmit_apdu(card, &apdu);
  314|     78|	LOG_TEST_RET(card->ctx, rv, "Failed to send Get Data ext. APDU");
  ------------------
  |  |  174|     78|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     78|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     78|	int _ret = (r); \
  |  |  |  |  168|     78|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 74]
  |  |  |  |  ------------------
  |  |  |  |  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|     78|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 74]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|     74|	return (apdu.sw1 == 0x90 && apdu.sw2 == 0x00);
  ------------------
  |  Branch (315:10): [True: 54, False: 20]
  |  Branch (315:30): [True: 54, False: 0]
  ------------------
  316|     78|}
card-starcos.c:starcos_determine_pin_encoding:
  269|    912|{
  270|    912|	unsigned int pin_format = PIN_FORMAT_DEFAULT;
  ------------------
  |  |  107|    912|#define PIN_FORMAT_DEFAULT		PIN_FORMAT_F2
  |  |  ------------------
  |  |  |  |  101|    912|#define PIN_FORMAT_F2			0x12
  |  |  ------------------
  ------------------
  271|    912|	unsigned int encoding = PIN_ENCODING_DETERMINE;
  ------------------
  |  |   96|    912|#define PIN_ENCODING_DETERMINE	0
  ------------------
  272|       |
  273|    912|	if ( IS_V34(card) ) {
  ------------------
  |  |  119|    912|#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: 598, False: 314]
  |  |  |  Branch (119:65): [True: 0, False: 314]
  |  |  ------------------
  ------------------
  274|    598|		starcos_determine_pin_format34(card, &pin_format);
  275|    598|	} else if ( IS_V35(card) ) {
  ------------------
  |  |  120|    314|#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: 99, False: 215]
  |  |  |  Branch (120:65): [True: 0, False: 215]
  |  |  ------------------
  ------------------
  276|     99|		starcos_determine_pin_format35(card, &pin_format);
  277|     99|	}
  278|       |
  279|    912|	switch (pin_format) {
  ------------------
  |  Branch (279:10): [True: 880, False: 32]
  ------------------
  280|      1|	case PIN_FORMAT_PW_ASCII:
  ------------------
  |  |  105|      1|#define PIN_FORMAT_PW_ASCII		0x21
  ------------------
  |  Branch (280:2): [True: 1, False: 911]
  ------------------
  281|      2|	case PIN_FORMAT_ASCII:
  ------------------
  |  |  104|      2|#define PIN_FORMAT_ASCII		0x14
  ------------------
  |  Branch (281:2): [True: 1, False: 911]
  ------------------
  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: 911]
  ------------------
  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: 911]
  ------------------
  288|    877|	case PIN_FORMAT_F2:
  ------------------
  |  |  101|    877|#define PIN_FORMAT_F2			0x12
  ------------------
  |  Branch (288:2): [True: 876, False: 36]
  ------------------
  289|    877|		encoding = SC_PIN_ENCODING_GLP;
  ------------------
  |  |  434|    877|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  290|    877|		break;
  291|    912|	}
  292|       |
  293|    912|	sc_log(card->ctx, "Determined PIN encoding: %d", encoding);
  ------------------
  |  |   71|    912|#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|    912|	return encoding;
  295|    912|}
card-starcos.c:starcos_determine_pin_format34:
  189|    598|{
  190|    598|	struct sc_context *ctx = card->ctx;
  191|    598|	struct sc_path path;
  192|    598|	struct sc_file *file;
  193|    598|	unsigned char buf[256];
  194|    598|	int rv;
  195|    598|	int retval = SC_SUCCESS;
  ------------------
  |  |   28|    598|#define SC_SUCCESS				0
  ------------------
  196|    598|	int rec_no=1;
  197|       |
  198|    598|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    598|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    598|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    598|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    598|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 598]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|    598|	sc_format_path(starcos_ef_pwdd, &path);
  201|    598|	rv = sc_select_file(card, &path, &file);
  202|    598|	LOG_TEST_RET(ctx, rv, "Cannot select EF.PWDD file");
  ------------------
  |  |  174|    598|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    598|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    598|	int _ret = (r); \
  |  |  |  |  168|    598|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 510, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  169|    510|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    510|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    510|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    510|		return _ret; \
  |  |  |  |  172|    510|	} \
  |  |  |  |  173|    598|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  203|       |
  204|     88|	if ( (rv = sc_read_record(card, rec_no, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0 ) {
  ------------------
  |  | 1305|     88|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (204:7): [True: 53, False: 35]
  ------------------
  205|     53|		starcos_ctrl_ref_template ctrl_ref_template;
  206|     53|		memset((void*)&ctrl_ref_template, 0, sizeof(ctrl_ref_template));
  207|     53|		rv = starcos_parse_supported_sec_mechanisms(card, buf, rv, &ctrl_ref_template);
  208|     53|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|     53|#define SC_SUCCESS				0
  ------------------
  |  Branch (208:8): [True: 34, False: 19]
  ------------------
  209|     34|			*pin_format = ctrl_ref_template.transmission_format;
  210|     34|			sc_log(ctx, "Determined StarCOS 3.4 PIN format: 0x%x", *pin_format);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  211|     34|		} else {
  212|     19|			sc_log(ctx, "Failed to parse record %d of EF.PWD, err=%d", rec_no, rv);
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  213|     19|			retval = rv;
  214|     19|		}
  215|     53|	} else {
  216|     35|		sc_log(ctx, "Failed to read record %d of EF.PWDD, err=%d", rec_no, rv);
  ------------------
  |  |   71|     35|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  217|     35|		retval = rv;
  218|     35|	}
  219|       |
  220|     88|	sc_file_free(file);
  221|     88|	LOG_FUNC_RETURN(ctx, retval);
  ------------------
  |  |  164|     88|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     88|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     88|	int _ret = r; \
  |  |  |  |  155|     88|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 88, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     88|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 36]
  |  |  |  |  ------------------
  |  |  |  |  157|     88|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     88|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     88|	return _ret; \
  |  |  |  |  163|     88|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|     88|}
card-starcos.c:starcos_parse_supported_sec_mechanisms:
  158|    945|{
  159|    945|	struct sc_context *ctx = card->ctx;
  160|    945|	const unsigned char *supported_sec_mechanisms_tag = NULL;
  161|    945|	size_t taglen;
  162|       |
  163|    945|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    945|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    945|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    945|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    945|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 945]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|       |
  165|    945|	supported_sec_mechanisms_tag = sc_asn1_find_tag(ctx, buf, buflen, TAG_STARCOS3X_SUPPORTED_SEC_MECHANISMS_tag, &taglen);
  ------------------
  |  |  146|    945|#define TAG_STARCOS3X_SUPPORTED_SEC_MECHANISMS_tag		0x7B
  ------------------
  166|    945|	if (supported_sec_mechanisms_tag != NULL && taglen >= 1)   {
  ------------------
  |  Branch (166:6): [True: 603, False: 342]
  |  Branch (166:46): [True: 429, False: 174]
  ------------------
  167|    429|		const unsigned char *tx_fmt_tag = NULL;
  168|    429|		const unsigned char *ctrl_ref_template_tag = NULL;
  169|    429|		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|    429|		ctrl_ref_template_tag = sc_asn1_find_tag(ctx, supported_sec_mechanisms_tag, taglen, TAG_STARCOS3X_CTRL_REF_TEMPLATE, &taglen);
  ------------------
  |  |  147|    429|#define TAG_STARCOS3X_CTRL_REF_TEMPLATE				0xA4
  ------------------
  173|    429|		if ( ctrl_ref_template_tag == NULL || taglen == 0 ) {
  ------------------
  |  Branch (173:8): [True: 232, False: 197]
  |  Branch (173:41): [True: 187, False: 10]
  ------------------
  174|    419|			ctrl_ref_template_tag = supported_sec_mechanisms_tag;
  175|    419|			taglen = supported_sec_mechanisms_taglen;
  176|    419|		}
  177|       |
  178|    429|		tx_fmt_tag = sc_asn1_find_tag(ctx, ctrl_ref_template_tag, taglen, TAG_STARCOS3X_TRANSMISSION_FORMAT, &taglen);
  ------------------
  |  |  148|    429|#define TAG_STARCOS3X_TRANSMISSION_FORMAT			0x89
  ------------------
  179|    429|		if ( tx_fmt_tag != NULL && taglen >= 1 ) {
  ------------------
  |  Branch (179:8): [True: 209, False: 220]
  |  Branch (179:30): [True: 36, False: 173]
  ------------------
  180|     36|			ctrl_ref_template->transmission_format = *(tx_fmt_tag + 0);
  181|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|     36|		}
  183|    429|	}
  184|       |
  185|    909|	LOG_FUNC_RETURN(ctx, SC_ERROR_TEMPLATE_NOT_FOUND);
  ------------------
  |  |  164|    909|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    909|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    909|	int _ret = r; \
  |  |  |  |  155|    909|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 909, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    909|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    909|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 909, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    909|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    909|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    909|	return _ret; \
  |  |  |  |  163|    909|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  186|    909|}
card-starcos.c:starcos_determine_pin_format35:
  225|     99|{
  226|     99|	struct sc_context *ctx = card->ctx;
  227|     99|	struct sc_path path;
  228|     99|	struct sc_file *file;
  229|     99|	unsigned char buf[256];
  230|     99|	int rv;
  231|     99|	int retval = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|     99|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  232|     99|	int rec_no=1;
  233|     99|	starcos_ctrl_ref_template ctrl_ref_template;
  234|       |
  235|     99|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     99|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     99|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     99|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     99|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 99]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|       |
  237|     99|	sc_format_path(starcos_ef_keyd, &path);
  238|     99|	rv = sc_select_file(card, &path, &file);
  239|     99|	LOG_TEST_RET(ctx, rv, "Cannot select EF.KEYD file");
  ------------------
  |  |  174|     99|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     99|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     99|	int _ret = (r); \
  |  |  |  |  168|     99|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 79]
  |  |  |  |  ------------------
  |  |  |  |  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|     99|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 79]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|       |
  241|  1.66k|	while ( (rv = sc_read_record(card, rec_no++, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR)) > 0 ) {
  ------------------
  |  | 1305|  1.66k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (241:10): [True: 1.59k, False: 77]
  ------------------
  242|  1.59k|		if ( buf[0] != TAG_STARCOS35_PIN_REFERENCE ) continue;
  ------------------
  |  |  145|  1.59k|#define TAG_STARCOS35_PIN_REFERENCE					0x88
  ------------------
  |  Branch (242:8): [True: 699, False: 892]
  ------------------
  243|       |
  244|    892|		memset((void*)&ctrl_ref_template, 0, sizeof(ctrl_ref_template));
  245|    892|		rv = starcos_parse_supported_sec_mechanisms(card, buf, rv, &ctrl_ref_template);
  246|    892|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|    892|#define SC_SUCCESS				0
  ------------------
  |  Branch (246:8): [True: 2, False: 890]
  ------------------
  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|    890|		} else {
  253|    890|			sc_log(ctx, "Failed to parse record %d of EF.KEYD, err=%d", rec_no-1, rv);
  ------------------
  |  |   71|    890|#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|    890|			retval = rv;
  255|    890|		}
  256|    892|	}
  257|       |
  258|     79|	sc_file_free(file);
  259|     79|	LOG_FUNC_RETURN(ctx, retval);
  ------------------
  |  |  164|     79|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     79|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     79|	int _ret = r; \
  |  |  |  |  155|     79|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 79, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     79|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     77|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 77, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|     79|}
card-starcos.c:starcos_has_esign_app:
  339|    598|static int starcos_has_esign_app(sc_card_t * card) {
  340|    598|	static const char * starcos_esign_aid = "A0:00:00:02:45:53:69:67:6E";
  341|    598|	int rv;
  342|       |
  343|    598|	rv = starcos_select_mf(card);
  344|    598|	if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|    598|#define SC_SUCCESS				0
  ------------------
  |  Branch (344:7): [True: 590, False: 8]
  ------------------
  345|    590|		u8 aid[SC_MAX_PATH_SIZE];
  346|    590|		size_t len = sizeof(aid);
  347|       |
  348|    590|		rv = sc_hex_to_bin(starcos_esign_aid, aid, &len);
  349|    590|		LOG_TEST_RET(card->ctx, rv, "Failed to convert eSing AID");
  ------------------
  |  |  174|    590|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    590|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    590|	int _ret = (r); \
  |  |  |  |  168|    590|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 590]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    590|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 590]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  350|    590|		rv = starcos_select_aid(card, aid, len, NULL);
  351|    590|		if ( rv == SC_SUCCESS ) {
  ------------------
  |  |   28|    590|#define SC_SUCCESS				0
  ------------------
  |  Branch (351:8): [True: 177, False: 413]
  ------------------
  352|    177|			starcos_select_mf(card);
  353|    177|		}
  354|    590|	}
  355|    598|	return ( rv == SC_SUCCESS );
  ------------------
  |  |   28|    598|#define SC_SUCCESS				0
  ------------------
  356|    598|}
card-starcos.c:starcos_select_mf:
  318|    775|static int starcos_select_mf(sc_card_t * card) {
  319|    775|	sc_apdu_t apdu;
  320|    775|	const u8 mf_buf[2] = {0x3f, 0x00};
  321|       |
  322|    775|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|    775|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  323|    775|	apdu.le = 0;
  324|    775|	apdu.lc = 2;
  325|    775|	apdu.data    = mf_buf;
  326|    775|	apdu.datalen = 2;
  327|    775|	apdu.resplen = 0;
  328|       |
  329|    775|	return sc_transmit_apdu(card, &apdu);
  330|    775|}
card-starcos.c:starcos_select_aid:
  749|  2.47k|{
  750|  2.47k|	sc_apdu_t apdu;
  751|  2.47k|	int r;
  752|  2.47k|	size_t i = 0;
  753|       |
  754|  2.47k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x04, 0x0C);
  ------------------
  |  |  293|  2.47k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  755|  2.47k|	apdu.lc = len;
  756|  2.47k|	apdu.data = (u8*)aid;
  757|  2.47k|	apdu.datalen = len;
  758|  2.47k|	apdu.resplen = 0;
  759|  2.47k|	apdu.le = 0;
  760|  2.47k|	r = sc_transmit_apdu(card, &apdu);
  761|  2.47k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  2.47k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.47k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.47k|	int _ret = (r); \
  |  |  |  |  168|  2.47k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 2.46k]
  |  |  |  |  ------------------
  |  |  |  |  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|  2.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.46k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  762|       |
  763|       |	/* check return value */
  764|  2.46k|	if (!(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) && apdu.sw1 != 0x61 )
  ------------------
  |  Branch (764:8): [True: 683, False: 1.78k]
  |  Branch (764:28): [True: 575, False: 108]
  |  Branch (764:49): [True: 1.89k, False: 0]
  ------------------
  765|  1.89k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  1.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.89k|	int _ret = r; \
  |  |  155|  1.89k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.89k, False: 0]
  |  |  ------------------
  |  |  156|  1.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.89k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.89k, False: 0]
  |  |  ------------------
  |  |  157|  1.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.89k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.89k|	return _ret; \
  |  |  163|  1.89k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  766|       |
  767|    575|	if (file_out) {
  ------------------
  |  Branch (767:6): [True: 0, False: 575]
  ------------------
  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|    575|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    575|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    575|	int _ret = r; \
  |  |  155|    575|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 575, False: 0]
  |  |  ------------------
  |  |  156|    575|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 575]
  |  |  ------------------
  |  |  157|    575|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    575|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    575|	return _ret; \
  |  |  163|    575|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  785|    575|}
card-starcos.c:starcos_finish:
  470|    912|{
  471|    912|	if (card->drv_data)
  ------------------
  |  Branch (471:6): [True: 912, False: 0]
  ------------------
  472|    912|		free((starcos_ex_data *)card->drv_data);
  473|    912|	return 0;
  474|    912|}
card-starcos.c:starcos_select_file:
  917|  9.20k|{
  918|  9.20k|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  919|  9.20k|	int    r, pathtype;
  920|  9.20k|	size_t i, pathlen;
  921|       |
  922|  9.20k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.20k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.20k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.20k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.20k]
  |  |  ------------------
  ------------------
  923|       |
  924|  9.20k|	if ( in_path->len > sizeof(pathbuf) ) {
  ------------------
  |  Branch (924:7): [True: 0, False: 9.20k]
  ------------------
  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|  9.20k|	memcpy(path, in_path->value, in_path->len);
  928|  9.20k|	pathlen = in_path->len;
  929|  9.20k|	pathtype = in_path->type;
  930|       |
  931|  9.20k|	if (in_path->aid.len) {
  ------------------
  |  Branch (931:6): [True: 99, False: 9.10k]
  ------------------
  932|     99|		if (!pathlen) {
  ------------------
  |  Branch (932:7): [True: 0, False: 99]
  ------------------
  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|     99|		} else {
  940|     99|			r = starcos_select_aid(card, in_path->aid.value, in_path->aid.len, NULL);
  941|     99|			LOG_TEST_RET(card->ctx, r, "Could not select AID!");
  ------------------
  |  |  174|     99|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     99|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     99|	int _ret = (r); \
  |  |  |  |  168|     99|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 96, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|     96|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     96|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     96|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     96|		return _ret; \
  |  |  |  |  172|     96|	} \
  |  |  |  |  173|     99|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  942|       |
  943|      3|			if (pathtype == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|      3|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (943:8): [True: 0, False: 3]
  ------------------
  944|      0|				pathtype = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  945|      0|			}
  946|      3|		}
  947|     99|	}
  948|       |
  949|  9.10k|	if (pathtype == SC_PATH_TYPE_FILE_ID)
  ------------------
  |  |  117|  9.10k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (949:6): [True: 0, False: 9.10k]
  ------------------
  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|  9.10k|	else if (pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  9.10k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (958:11): [True: 1.79k, False: 7.31k]
  ------------------
  959|  1.79k|	{	/* SELECT DF with AID */
  960|       |		/* Select with 1-16byte Application-ID */
  961|  1.79k|		r = starcos_select_aid(card, pathbuf, pathlen, file_out);
  962|  1.79k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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.39k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.39k, False: 395]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  963|  1.79k|	}
  964|  7.31k|	else if (pathtype == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  7.31k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (964:11): [True: 7.31k, False: 0]
  ------------------
  965|  7.31k|	{
  966|  7.31k|		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|  7.31k|		if (pathlen%2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (974:7): [True: 0, False: 7.31k]
  |  Branch (974:25): [True: 1, False: 7.31k]
  |  Branch (974:40): [True: 0, False: 7.31k]
  ------------------
  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|  7.31k|		if (pathlen == 6 && ( path[0] != 0x3f || path[1] != 0x00 ))
  ------------------
  |  Branch (977:7): [True: 542, False: 6.77k]
  |  Branch (977:25): [True: 1, False: 541]
  |  Branch (977:44): [True: 2, False: 539]
  ------------------
  978|      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]
  |  |  ------------------
  ------------------
  979|       |
  980|  7.31k|		if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  14.6k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  7.31k|#define IS_V34(card) card->type == SC_CARD_TYPE_STARCOS_V3_4 || card->type == SC_CARD_TYPE_STARCOS_V3_4_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (119:22): [True: 2.69k, False: 4.61k]
  |  |  |  |  |  Branch (119:65): [True: 1.81k, False: 2.79k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  2.79k|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 496, False: 2.30k]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 2.30k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  981|       |			/* unify path (the first FID should be MF) */
  982|  5.00k|			if (path[0] != 0x3f || path[1] != 0x00)
  ------------------
  |  Branch (982:8): [True: 345, False: 4.66k]
  |  Branch (982:27): [True: 0, False: 4.66k]
  ------------------
  983|    345|			{
  984|    345|				n_pathbuf[0] = 0x3f;
  985|    345|				n_pathbuf[1] = 0x00;
  986|    345|				memcpy(n_pathbuf+2, path, pathlen);
  987|    345|				path = n_pathbuf;
  988|    345|				pathlen += 2;
  989|    345|			}
  990|  5.00k|		}
  991|       |
  992|  9.04k|		for ( i=0; i<pathlen-2; i+=2 )
  ------------------
  |  Branch (992:14): [True: 7.18k, False: 1.85k]
  ------------------
  993|  7.18k|		{
  994|  7.18k|			r = starcos_select_fid(card, path[i], path[i+1], NULL, 0);
  995|  7.18k|			LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|  7.18k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.18k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.18k|	int _ret = (r); \
  |  |  |  |  168|  7.18k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.45k, False: 1.73k]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.45k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.45k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.45k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.45k|		return _ret; \
  |  |  |  |  172|  5.45k|	} \
  |  |  |  |  173|  7.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.73k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  996|  7.18k|		}
  997|  1.85k|		r = starcos_select_fid(card, path[pathlen-2], path[pathlen-1], file_out, 1);
  998|  1.85k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  1.85k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.85k|	int _ret = r; \
  |  |  155|  1.85k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.85k, False: 0]
  |  |  ------------------
  |  |  156|  1.85k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    530|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 530, False: 1.32k]
  |  |  ------------------
  |  |  157|  1.85k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.85k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.85k|	return _ret; \
  |  |  163|  1.85k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  999|  1.85k|	}
 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|  9.10k|}
card-starcos.c:starcos_select_fid:
  790|  9.04k|{
  791|  9.04k|	sc_apdu_t apdu;
  792|  9.04k|	u8 data[] = {id_hi & 0xff, id_lo & 0xff};
  793|  9.04k|	u8 resp[SC_MAX_APDU_BUFFER_SIZE];
  794|  9.04k|	int bIsDF = 0, r;
  795|  9.04k|	int isFCP = 0;
  796|  9.04k|	int isMF = 0;
  797|       |
  798|       |	/* request FCI to distinguish between EFs and DFs */
  799|  9.04k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  9.04k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  800|  9.04k|	apdu.p2   = 0x00;
  801|  9.04k|	apdu.resp = (u8*)resp;
  802|  9.04k|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|  9.04k|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  803|  9.04k|	apdu.le = 256;
  804|  9.04k|	apdu.lc = 2;
  805|  9.04k|	apdu.data = (u8*)data;
  806|  9.04k|	apdu.datalen = 2;
  807|       |
  808|  9.04k|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  18.0k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  9.04k|#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.27k, False: 5.76k]
  |  |  |  |  |  Branch (119:65): [True: 2.34k, False: 3.42k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  3.42k|#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: 614, False: 2.80k]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 2.80k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|  6.23k|		if (id_hi == 0x3f && id_lo == 0x0) {
  ------------------
  |  Branch (809:7): [True: 5.00k, False: 1.22k]
  |  Branch (809:24): [True: 5.00k, False: 0]
  ------------------
  810|  5.00k|			apdu.p1 = 0x0;
  811|  5.00k|			apdu.p2 = 0x0C;
  812|  5.00k|			apdu.le = 0;
  813|  5.00k|			apdu.resplen = 0;
  814|  5.00k|			apdu.resp = NULL;
  815|  5.00k|			apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  5.00k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  816|  5.00k|			isMF = 1;
  817|  5.00k|		} else if (file_out || is_file) {
  ------------------
  |  Branch (817:14): [True: 791, False: 437]
  |  Branch (817:26): [True: 331, False: 106]
  ------------------
  818|       |			// last component (i.e. file or path)
  819|  1.12k|			apdu.p1 = 0x2;
  820|  1.12k|			apdu.p2 = 0x4;
  821|  1.12k|		} else {
  822|       |			// path component
  823|    106|			apdu.p1 = 0x1;
  824|    106|			apdu.p2 = 0x0;
  825|    106|		}
  826|  6.23k|	}
  827|       |
  828|  9.04k|	r = sc_transmit_apdu(card, &apdu);
  829|  9.04k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  9.04k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  9.04k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  9.04k|	int _ret = (r); \
  |  |  |  |  168|  9.04k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 132, False: 8.91k]
  |  |  |  |  ------------------
  |  |  |  |  169|    132|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    132|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    132|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    132|		return _ret; \
  |  |  |  |  172|    132|	} \
  |  |  |  |  173|  9.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8.91k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  830|       |
  831|  8.91k|	if (apdu.p2 == 0x00 && apdu.sw1 == 0x62 && apdu.sw2 == 0x84 ) {
  ------------------
  |  Branch (831:6): [True: 2.87k, False: 6.04k]
  |  Branch (831:25): [True: 53, False: 2.81k]
  |  Branch (831:45): [True: 30, False: 23]
  ------------------
  832|       |		/* no FCI => we have a DF (see comment in process_fci()) */
  833|     30|		bIsDF = 1;
  834|     30|		apdu.p2 = 0x0C;
  835|     30|		apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     30|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  836|     30|		apdu.resplen = 0;
  837|     30|		apdu.le = 0;
  838|     30|		r = sc_transmit_apdu(card, &apdu);
  839|     30|		LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
  ------------------
  |  |  174|     30|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     30|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     30|	int _ret = (r); \
  |  |  |  |  168|     30|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 20]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  840|  8.88k|	} else if ((IS_V3x(card))
  ------------------
  |  |  121|  8.88k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  8.88k|#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.64k]
  |  |  |  |  |  Branch (119:65): [True: 2.30k, False: 3.33k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|  3.33k|#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: 605, False: 2.73k]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 2.73k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  841|  6.14k|			&& apdu.p2 == 0x4 && apdu.sw1 == 0x6a && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (841:7): [True: 1.11k, False: 5.03k]
  |  Branch (841:25): [True: 218, False: 892]
  |  Branch (841:45): [True: 195, False: 23]
  ------------------
  842|       |		/* not a file, could be a path */
  843|    195|		bIsDF = 1;
  844|    195|		apdu.p1 = 0x1;
  845|    195|		apdu.p2 = 0x0;
  846|    195|		apdu.resplen = sizeof(resp);
  847|    195|		apdu.le = 256;
  848|    195|		apdu.lc = 2;
  849|    195|		r = sc_transmit_apdu(card, &apdu);
  850|    195|		LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
  ------------------
  |  |  174|    195|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    195|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    195|	int _ret = (r); \
  |  |  |  |  168|    195|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  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|    195|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|  8.68k|	} else if (apdu.sw1 == 0x61 || (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && !isMF)) {
  ------------------
  |  Branch (851:13): [True: 0, False: 8.68k]
  |  Branch (851:34): [True: 3.38k, False: 5.29k]
  |  Branch (851:54): [True: 3.10k, False: 281]
  |  Branch (851:74): [True: 1.81k, False: 1.29k]
  ------------------
  852|       |		/* SELECT returned some data (possible FCI) =>
  853|       |		 * try a READ BINARY to see if a EF is selected */
  854|  1.81k|		sc_apdu_t apdu2;
  855|  1.81k|		u8 resp2[2];
  856|  1.81k|		sc_format_apdu(card, &apdu2, SC_APDU_CASE_2_SHORT, 0xB0, 0, 0);
  ------------------
  |  |  292|  1.81k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  857|  1.81k|		apdu2.resp = (u8*)resp2;
  858|  1.81k|		apdu2.resplen = 2;
  859|  1.81k|		apdu2.le = 1;
  860|  1.81k|		apdu2.lc = 0;
  861|  1.81k|		r = sc_transmit_apdu(card, &apdu2);
  862|  1.81k|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 26, False: 1.78k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.81k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  863|  1.78k|		if (apdu2.sw1 == 0x69 && apdu2.sw2 == 0x86) {
  ------------------
  |  Branch (863:7): [True: 49, False: 1.74k]
  |  Branch (863:28): [True: 21, False: 28]
  ------------------
  864|       |			/* no current EF is selected => we have a DF */
  865|     21|			bIsDF = 1;
  866|  1.76k|		} else {
  867|  1.76k|			isFCP = 1;
  868|  1.76k|		}
  869|  1.78k|	}
  870|       |
  871|  8.86k|	if (apdu.sw1 != 0x61 && (apdu.sw1 != 0x90 || apdu.sw2 != 0x00))
  ------------------
  |  Branch (871:6): [True: 8.86k, False: 0]
  |  Branch (871:27): [True: 5.31k, False: 3.55k]
  |  Branch (871:47): [True: 284, False: 3.26k]
  ------------------
  872|  5.59k|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  5.59k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  5.59k|	int _ret = r; \
  |  |  155|  5.59k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 5.59k, False: 0]
  |  |  ------------------
  |  |  156|  5.59k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  5.59k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 5.59k, False: 0]
  |  |  ------------------
  |  |  157|  5.59k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  5.59k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  5.59k|	return _ret; \
  |  |  163|  5.59k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  873|       |
  874|  3.26k|	if (file_out) {
  ------------------
  |  Branch (874:6): [True: 881, False: 2.38k]
  ------------------
  875|    881|		sc_file_t *file = sc_file_new();
  876|    881|		if (!file)
  ------------------
  |  Branch (876:7): [True: 0, False: 881]
  ------------------
  877|    881|			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|    881|		file->id = (id_hi << 8) + id_lo;
  879|       |
  880|    881|		if (bIsDF || isMF) {
  ------------------
  |  Branch (880:7): [True: 180, False: 701]
  |  Branch (880:16): [True: 0, False: 701]
  ------------------
  881|       |			/* we have a DF */
  882|    180|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    180|#define SC_FILE_TYPE_DF			0x04
  ------------------
  883|    180|			file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|    180|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  884|    180|			file->size = 0;
  885|    180|			file->namelen = 0;
  886|    180|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    180|#define SC_FILE_MAGIC			0x14426950
  ------------------
  887|    180|			*file_out = file;
  888|    701|		} else {
  889|       |			/* ok, assume we have a EF */
  890|    701|			if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  1.40k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    701|#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: 324, False: 377]
  |  |  |  |  |  Branch (119:65): [True: 185, False: 192]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|    192|#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: 17, False: 175]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 175]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  891|    526|				if (isFCP) {
  ------------------
  |  Branch (891:9): [True: 526, False: 0]
  ------------------
  892|    526|					r = process_fcp_v3_4(card->ctx, file, apdu.resp,
  893|    526|							apdu.resplen);
  894|    526|				} else {
  895|      0|					r = process_fci_v3_4(card->ctx, file, apdu.resp,
  896|      0|							apdu.resplen);
  897|      0|				}
  898|    526|			} else {
  899|    175|				r = process_fci(card->ctx, file, apdu.resp,
  900|    175|						apdu.resplen);
  901|    175|			}
  902|    701|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    701|#define SC_SUCCESS				0
  ------------------
  |  Branch (902:8): [True: 206, False: 495]
  ------------------
  903|    206|				sc_file_free(file);
  904|    206|				return r;
  905|    206|			}
  906|       |
  907|    495|			*file_out = file;
  908|    495|		}
  909|    881|	}
  910|       |
  911|  3.06k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|  3.06k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.06k|	int _ret = r; \
  |  |  155|  3.06k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.06k, False: 0]
  |  |  ------------------
  |  |  156|  3.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: 3.06k]
  |  |  ------------------
  |  |  157|  3.06k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.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|  3.06k|	return _ret; \
  |  |  163|  3.06k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  912|  3.06k|}
card-starcos.c:process_fcp_v3_4:
  606|    526|{
  607|    526|	size_t taglen, len = buflen;
  608|    526|	const u8 *tag = NULL, *p;
  609|       |
  610|    526|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  611|    526|		 "processing %"SC_FORMAT_LEN_SIZE_T"u FCP bytes\n", buflen);
  612|       |
  613|    526|	if (buflen < 2)
  ------------------
  |  Branch (613:6): [True: 70, False: 456]
  ------------------
  614|     70|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     70|#define SC_ERROR_INTERNAL			-1400
  ------------------
  615|    456|	if (buf[0] != 0x62)
  ------------------
  |  Branch (615:6): [True: 10, False: 446]
  ------------------
  616|     10|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     10|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  617|    446|	len = (size_t)buf[1];
  618|    446|	if (buflen - 2 < len)
  ------------------
  |  Branch (618:6): [True: 12, False: 434]
  ------------------
  619|     12|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     12|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  620|    434|	p = buf + 2;
  621|       |
  622|    434|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  623|    434|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (623:6): [True: 18, False: 416]
  |  Branch (623:21): [True: 7, False: 11]
  ------------------
  624|      7|		int bytes = (tag[0] << 8) + tag[1];
  625|      7|		sc_log(ctx,
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  626|      7|			"  bytes in file: %d\n", bytes);
  627|      7|		file->size = bytes;
  628|      7|	}
  629|       |
  630|    434|	tag = sc_asn1_find_tag(ctx, p, len, 0xc5, &taglen);
  631|    434|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (631:6): [True: 16, False: 418]
  |  Branch (631:21): [True: 6, False: 10]
  ------------------
  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|    434|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  639|    434|	if (tag != NULL) {
  ------------------
  |  Branch (639:6): [True: 83, False: 351]
  ------------------
  640|     83|		const char *type = "unknown";
  641|     83|		const char *structure = "unknown";
  642|       |
  643|     83|		if (taglen >= 1) {
  ------------------
  |  Branch (643:7): [True: 72, False: 11]
  ------------------
  644|     72|			unsigned char byte = tag[0];
  645|     72|			if (byte & 0x40) {
  ------------------
  |  Branch (645:8): [True: 38, False: 34]
  ------------------
  646|     38|				file->shareable = 1;
  647|     38|			}
  648|     72|			if (byte == 0x38) {
  ------------------
  |  Branch (648:8): [True: 10, False: 62]
  ------------------
  649|     10|				type = "DF";
  650|     10|				file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     10|#define SC_FILE_TYPE_DF			0x04
  ------------------
  651|     10|				file->shareable = 1;
  652|     10|			}
  653|     72|			switch (byte & 7) {
  654|     12|			case 1:
  ------------------
  |  Branch (654:4): [True: 12, False: 60]
  ------------------
  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|     12|			case 2:
  ------------------
  |  Branch (661:4): [True: 12, False: 60]
  ------------------
  662|       |				/* linear fixed EF */
  663|     12|				type = "working EF";
  664|     12|				structure = "linear fixed";
  665|     12|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     12|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  666|     12|				file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     12|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  667|     12|				break;
  668|     11|			case 4:
  ------------------
  |  Branch (668:4): [True: 11, False: 61]
  ------------------
  669|       |				/* linear variable EF */
  670|     11|				type = "working EF";
  671|     11|				structure = "linear variable";
  672|     11|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     11|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  673|     11|				file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|     11|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  674|     11|				break;
  675|     11|			case 6:
  ------------------
  |  Branch (675:4): [True: 11, False: 61]
  ------------------
  676|       |				/* cyclic EF */
  677|     11|				type = "working EF";
  678|     11|				structure = "cyclic";
  679|     11|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     11|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  680|     11|				file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|     11|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  681|     11|				break;
  682|     26|			default:
  ------------------
  |  Branch (682:4): [True: 26, False: 46]
  ------------------
  683|       |				/* use defaults from above */
  684|     26|				break;
  685|     72|			}
  686|     72|		}
  687|     83|		sc_log(ctx,
  ------------------
  |  |   71|     83|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  688|     83|			"  type: %s\n", type);
  689|     83|		sc_log(ctx,
  ------------------
  |  |   71|     83|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  690|     83|			"  EF structure: %s\n", structure);
  691|     83|		if (taglen >= 2) {
  ------------------
  |  Branch (691:7): [True: 68, False: 15]
  ------------------
  692|     68|			if (tag[1] != 0x41 || taglen != 5) {
  ------------------
  |  Branch (692:8): [True: 58, False: 10]
  |  Branch (692:26): [True: 10, False: 0]
  ------------------
  693|     68|				SC_FUNC_RETURN(ctx, 2,SC_ERROR_INVALID_DATA);
  ------------------
  |  |  153|     68|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     68|	int _ret = r; \
  |  |  155|     68|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 68, False: 0]
  |  |  ------------------
  |  |  156|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     68|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 68, False: 0]
  |  |  ------------------
  |  |  157|     68|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     68|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     68|	return _ret; \
  |  |  163|     68|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  694|     68|			}
  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|     83|	}
  703|       |
  704|    366|	tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
  705|    366|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (705:6): [True: 106, False: 260]
  |  Branch (705:21): [True: 3, False: 103]
  ------------------
  706|      3|		file->id = (tag[0] << 8) | tag[1];
  707|      3|		sc_log(ctx,  "  file identifier: 0x%02X%02X\n",
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  708|      3|			tag[0], tag[1]);
  709|      3|	}
  710|       |
  711|    366|	tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
  712|    366|	if (tag != NULL && taglen > 0 && taglen <= 16) {
  ------------------
  |  Branch (712:6): [True: 16, False: 350]
  |  Branch (712:21): [True: 4, False: 12]
  |  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|    366|	tag = sc_asn1_find_tag(ctx, p, len, 0x8a, &taglen);
  720|    366|	if (tag != NULL && taglen == 1) {
  ------------------
  |  Branch (720:6): [True: 75, False: 291]
  |  Branch (720:21): [True: 5, False: 70]
  ------------------
  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|    366|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    366|#define SC_FILE_MAGIC			0x14426950
  ------------------
  743|    366|	return SC_SUCCESS;
  ------------------
  |  |   28|    366|#define SC_SUCCESS				0
  ------------------
  744|    366|}
card-starcos.c:process_fci:
  478|    175|{
  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|    175|	size_t taglen, len = buflen;
  486|    175|	const u8 *tag = NULL, *p;
  487|       |
  488|    175|	sc_log(ctx,  "processing FCI bytes\n");
  ------------------
  |  |   71|    175|#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|    175|	if (buflen < 2)
  ------------------
  |  Branch (490:6): [True: 20, False: 155]
  ------------------
  491|     20|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     20|#define SC_ERROR_INTERNAL			-1400
  ------------------
  492|    155|	if (buf[0] != 0x6f)
  ------------------
  |  Branch (492:6): [True: 16, False: 139]
  ------------------
  493|     16|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     16|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  494|    139|	len = (size_t)buf[1];
  495|    139|	if (buflen - 2 < len)
  ------------------
  |  Branch (495:6): [True: 10, False: 129]
  ------------------
  496|     10|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     10|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  497|    129|	p = buf + 2;
  498|       |
  499|       |	/* defaults */
  500|    129|	file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    129|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  501|    129|	file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|    129|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  502|    129|	file->shareable = 0;
  503|    129|	file->record_length = 0;
  504|    129|	file->size = 0;
  505|       |
  506|    129|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  507|    129|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (507:6): [True: 20, False: 109]
  |  Branch (507:21): [True: 13, False: 7]
  ------------------
  508|     13|		int bytes = (tag[0] << 8) + tag[1];
  509|     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__
  |  |  ------------------
  ------------------
  510|     13|			"  bytes in file: %d\n", bytes);
  511|     13|		file->size = bytes;
  512|     13|	}
  513|       |
  514|    129|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  515|    129|	if (tag != NULL) {
  ------------------
  |  Branch (515:6): [True: 45, False: 84]
  ------------------
  516|     45|		const char *type = "unknown";
  517|     45|		const char *structure = "unknown";
  518|       |
  519|     45|		if (taglen == 1 && tag[0] == 0x01) {
  ------------------
  |  Branch (519:7): [True: 27, False: 18]
  |  Branch (519:22): [True: 14, False: 13]
  ------------------
  520|       |			/* transparent EF */
  521|     14|			type = "working EF";
  522|     14|			structure = "transparent";
  523|     14|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     14|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  524|     14|			file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     14|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  525|     31|		} else if (taglen == 1 && tag[0] == 0x11) {
  ------------------
  |  Branch (525:14): [True: 13, False: 18]
  |  Branch (525:29): [True: 7, False: 6]
  ------------------
  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: 14, False: 10]
  |  Branch (531:29): [True: 4, False: 10]
  ------------------
  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|     45|		sc_log(ctx,
  ------------------
  |  |   71|     45|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  559|     45|			"  type: %s\n", type);
  560|     45|		sc_log(ctx,
  ------------------
  |  |   71|     45|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  561|     45|			"  EF structure: %s\n", structure);
  562|     45|	}
  563|    129|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    129|#define SC_FILE_MAGIC			0x14426950
  ------------------
  564|       |
  565|    129|	return SC_SUCCESS;
  ------------------
  |  |   28|    129|#define SC_SUCCESS				0
  ------------------
  566|    129|}
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.12k, False: 8.85k]
  |  Branch (1946:21): [True: 4.65k, False: 474]
  ------------------
 1947|  4.65k|		return SC_SUCCESS;
  ------------------
  |  |   28|  4.65k|#define SC_SUCCESS				0
  ------------------
 1948|  9.32k|	if (sw1 == 0x63 && (sw2 & ~0x0fU) == 0xc0 )
  ------------------
  |  Branch (1948:6): [True: 165, False: 9.16k]
  |  Branch (1948:21): [True: 35, False: 130]
  ------------------
 1949|     35|	{
 1950|     35|		sc_log(card->ctx,  "Verification failed (remaining tries: %d)\n",
  ------------------
  |  |   71|     35|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1951|     35|		(sw2 & 0x0f));
 1952|     35|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     35|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 1953|     35|	}
 1954|       |
 1955|       |	/* check starcos error messages */
 1956|   139k|	for (i = 0; i < err_count; i++)
  ------------------
  |  Branch (1956:14): [True: 129k, False: 9.27k]
  ------------------
 1957|   129k|		if (starcos_errors[i].SWs == ((sw1 << 8) | sw2))
  ------------------
  |  Branch (1957:7): [True: 22, False: 129k]
  ------------------
 1958|     22|		{
 1959|     22|			sc_log(card->ctx,  "%s\n", starcos_errors[i].errorstr);
  ------------------
  |  |   71|     22|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1960|     22|			return starcos_errors[i].errorno;
 1961|     22|		}
 1962|       |
 1963|       |	/* iso error */
 1964|  9.27k|	return iso_ops->check_sw(card, sw1, sw2);
 1965|  9.29k|}
card-starcos.c:starcos_set_security_env:
 1536|  2.13k|{
 1537|  2.13k|	u8              *p, *pp;
 1538|  2.13k|	int              r, operation = env->operation;
 1539|  2.13k|	sc_apdu_t   apdu;
 1540|  2.13k|	u8               sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1541|  2.13k|	starcos_ex_data *ex_data = (starcos_ex_data *)card->drv_data;
 1542|       |
 1543|  2.13k|	p     = sbuf;
 1544|       |
 1545|  2.13k|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  4.26k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|  2.13k|#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.18k, False: 946]
  |  |  |  |  |  Branch (119:65): [True: 817, False: 129]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|    129|#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: 129]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 129]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1546|  2.00k|		u8 algorithm_supported = (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1) ||
  ------------------
  |  |  120|  2.00k|#define SC_ALGORITHM_RSA_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|  2.00k|#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|  2.00k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (1546:28): [True: 260, False: 1.74k]
  ------------------
 1547|  1.74k|								(env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PSS);
  ------------------
  |  |  116|  1.74k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1547:9): [True: 751, False: 991]
  ------------------
 1548|  2.00k|		if (!algorithm_supported ||
  ------------------
  |  Branch (1548:7): [True: 991, False: 1.01k]
  ------------------
 1549|  1.01k|			!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || env->key_ref_len != 1) {
  ------------------
  |  |   67|  1.01k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1549:4): [True: 0, False: 1.01k]
  |  Branch (1549:50): [True: 0, False: 1.01k]
  ------------------
 1550|    991|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1551|    991|		}
 1552|       |
 1553|       |		/* Tag '84' (length 1) denotes key name or key reference */
 1554|  1.01k|		*p++ = 0x84;
 1555|  1.01k|		*p++ = 0x01;
 1556|  1.01k|		if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   66|  1.01k|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1556:7): [True: 43, False: 968]
  ------------------
 1557|     43|			*p++ = *env->key_ref | 0x80;
 1558|    968|		} else {
 1559|    968|			*p++ = *env->key_ref;
 1560|    968|		}
 1561|       |
 1562|  1.01k|		switch (operation) {
 1563|    900|			case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   57|    900|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1563:4): [True: 900, False: 111]
  ------------------
 1564|    900|				sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB6);
  ------------------
  |  |  293|    900|#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|    900|				*p++ = 0x89;
 1570|    900|				if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PSS) {
  ------------------
  |  |  116|    900|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1570:9): [True: 751, False: 149]
  ------------------
 1571|    751|					*p++ = 0x03;
 1572|    751|					*p++ = 0x13;
 1573|    751|					*p++ = 0x33;
 1574|    751|					*p++ = 0x30;
 1575|    751|				} else {
 1576|       |					// fall back, RSA PKCS1 Padding
 1577|    149|					*p++ = 0x02;
 1578|    149|					*p++ = 0x13;
 1579|    149|					*p++ = 0x23;
 1580|    149|				}
 1581|    900|				break;
 1582|       |
 1583|    111|			case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   56|    111|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1583:4): [True: 111, False: 900]
  ------------------
 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: 58, False: 53]
  |  |  |  Branch (119:65): [True: 53, 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: 1.01k]
  ------------------
 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|  1.01k|		}
 1604|       |
 1605|  1.01k|		apdu.data    = sbuf;
 1606|  1.01k|		apdu.datalen = p - sbuf;
 1607|  1.01k|		apdu.lc      = p - sbuf;
 1608|  1.01k|		apdu.le      = 0;
 1609|  1.01k|		r = sc_transmit_apdu(card, &apdu);
 1610|  1.01k|		LOG_TEST_RET(card->ctx, r, "APDU transmit 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: 18, False: 993]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 993]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1611|    993|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1611:7): [True: 680, False: 313]
  |  Branch (1611:27): [True: 27, False: 286]
  ------------------
 1612|    707|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|    707|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    707|	int _ret = r; \
  |  |  155|    707|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 707, False: 0]
  |  |  ------------------
  |  |  156|    707|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    707|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 707, False: 0]
  |  |  ------------------
  |  |  157|    707|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    707|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    707|	return _ret; \
  |  |  163|    707|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1613|       |
 1614|    286|		if ((operation == SC_SEC_OPERATION_SIGN && env->algorithm_flags == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |   57|    572|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
              		if ((operation == SC_SEC_OPERATION_SIGN && env->algorithm_flags == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  118|    260|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1614:8): [True: 260, False: 26]
  |  Branch (1614:46): [True: 68, False: 192]
  ------------------
 1615|    218|			|| (operation == SC_SEC_OPERATION_DECIPHER && env->algorithm_flags == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)) {
  ------------------
  |  |   56|    436|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
              			|| (operation == SC_SEC_OPERATION_DECIPHER && env->algorithm_flags == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)) {
  ------------------
  |  |  119|     26|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1615:8): [True: 26, False: 192]
  |  Branch (1615:50): [True: 26, False: 0]
  ------------------
 1616|       |			// input data will be already padded
 1617|     94|			ex_data->fix_digestInfo = 0;
 1618|    192|		} else {
 1619|    192|			ex_data->fix_digestInfo = env->algorithm_flags;
 1620|    192|		}
 1621|    286|		ex_data->sec_ops        = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   57|    286|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
 1622|    286|		return SC_SUCCESS;
  ------------------
  |  |   28|    286|#define SC_SUCCESS				0
  ------------------
 1623|    993|	}
 1624|       |
 1625|       |	/* copy key reference, if present */
 1626|    129|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   67|    129|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1626:6): [True: 129, False: 0]
  ------------------
 1627|    129|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   68|    129|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1627:7): [True: 0, False: 129]
  ------------------
 1628|      0|			*p++ = 0x83;
 1629|    129|		else
 1630|    129|			*p++ = 0x84;
 1631|    129|		*p++ = env->key_ref_len;
 1632|    129|		memcpy(p, env->key_ref, env->key_ref_len);
 1633|    129|		p += env->key_ref_len;
 1634|    129|	}
 1635|    129|	pp = p;
 1636|    129|	if (operation == SC_SEC_OPERATION_DECIPHER){
  ------------------
  |  |   56|    129|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1636:6): [True: 54, False: 75]
  ------------------
 1637|     54|		if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) {
  ------------------
  |  |  119|     54|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1637:7): [True: 40, False: 14]
  ------------------
 1638|     40|			*p++ = 0x80;
 1639|     40|			*p++ = 0x01;
 1640|     40|			*p++ = 0x02;
 1641|     40|		} else
 1642|     14|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     14|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1643|     40|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x81,
  ------------------
  |  |  293|     40|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1644|     40|		               0xb8);
 1645|     40|		apdu.data    = sbuf;
 1646|     40|		apdu.datalen = p - sbuf;
 1647|     40|		apdu.lc      = p - sbuf;
 1648|     40|		apdu.le      = 0;
 1649|     40|		r = sc_transmit_apdu(card, &apdu);
 1650|     40|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     40|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     40|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     40|	int _ret = (r); \
  |  |  |  |  168|     40|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  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|     40|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 37]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1651|     37|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1651:7): [True: 7, False: 30]
  |  Branch (1651:27): [True: 3, False: 27]
  ------------------
 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|     27|		return SC_SUCCESS;
  ------------------
  |  |   28|     27|#define SC_SUCCESS				0
  ------------------
 1654|     37|	}
 1655|       |	/* try COMPUTE SIGNATURE */
 1656|     75|	if (operation == SC_SEC_OPERATION_SIGN && (
  ------------------
  |  |   57|    150|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1656:6): [True: 75, False: 0]
  ------------------
 1657|     75|	    env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 ||
  ------------------
  |  |  118|    150|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1657:6): [True: 41, False: 34]
  ------------------
 1658|     54|	    env->algorithm_flags & SC_ALGORITHM_RSA_PAD_ISO9796)) {
  ------------------
  |  |  115|     34|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  |  Branch (1658:6): [True: 13, False: 21]
  ------------------
 1659|     54|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   65|     54|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1659:7): [True: 0, False: 54]
  ------------------
 1660|      0|			*p++ = 0x80;
 1661|      0|			*p++ = 0x01;
 1662|      0|			*p++ = env->algorithm_ref & 0xFF;
 1663|     54|		} else if (env->flags & SC_SEC_ENV_ALG_PRESENT &&
  ------------------
  |  |   69|    108|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (1663:14): [True: 54, False: 0]
  ------------------
 1664|     54|		            env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   78|     54|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1664:15): [True: 54, False: 0]
  ------------------
 1665|       |			/* set the method to use based on the algorithm_flags */
 1666|     54|			*p++ = 0x80;
 1667|     54|			*p++ = 0x01;
 1668|     54|			if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01) {
  ------------------
  |  |  118|     54|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1668:8): [True: 41, False: 13]
  ------------------
 1669|     41|				if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1)
  ------------------
  |  |  143|     41|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (1669:9): [True: 0, False: 41]
  ------------------
 1670|      0|					*p++ = 0x12;
 1671|     41|				else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_RIPEMD160)
  ------------------
  |  |  146|     41|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  |  Branch (1671:14): [True: 0, False: 41]
  ------------------
 1672|      0|					*p++ = 0x22;
 1673|     41|				else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_MD5)
  ------------------
  |  |  144|     41|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  |  Branch (1673:14): [True: 0, False: 41]
  ------------------
 1674|      0|					*p++ = 0x32;
 1675|     41|				else {
 1676|       |					/* can't use COMPUTE SIGNATURE =>
 1677|       |					 * try INTERNAL AUTHENTICATE */
 1678|     41|					p = pp;
 1679|     41|					operation = SC_SEC_OPERATION_AUTHENTICATE;
  ------------------
  |  |   58|     41|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
 1680|     41|					goto try_authenticate;
 1681|     41|				}
 1682|     41|			} 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|     54|		}
 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|     62|try_authenticate:
 1712|       |	/* try INTERNAL AUTHENTICATE */
 1713|     62|	if (operation == SC_SEC_OPERATION_AUTHENTICATE &&
  ------------------
  |  |   58|    124|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (1713:6): [True: 41, False: 21]
  ------------------
 1714|     41|	    env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1) {
  ------------------
  |  |  120|     41|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|     41|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|     41|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (1714:6): [True: 41, False: 0]
  ------------------
 1715|     41|		*p++ = 0x80;
 1716|     41|		*p++ = 0x01;
 1717|     41|		*p++ = 0x01;
 1718|     41|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41,
  ------------------
  |  |  293|     41|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1719|     41|		               0xa4);
 1720|     41|		apdu.data    = sbuf;
 1721|     41|		apdu.datalen = p - sbuf;
 1722|     41|		apdu.lc      = p - sbuf;
 1723|     41|		apdu.le      = 0;
 1724|     41|		r = sc_transmit_apdu(card, &apdu);
 1725|     41|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     41|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     41|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     41|	int _ret = (r); \
  |  |  |  |  168|     41|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 40]
  |  |  |  |  ------------------
  |  |  |  |  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|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 40]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1726|     40|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1726:7): [True: 3, False: 37]
  |  Branch (1726:27): [True: 3, False: 34]
  ------------------
 1727|      6|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1728|     34|		ex_data->fix_digestInfo = env->algorithm_flags;
 1729|     34|		ex_data->sec_ops        = SC_SEC_OPERATION_AUTHENTICATE;
  ------------------
  |  |   58|     34|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
 1730|     34|		return SC_SUCCESS;
  ------------------
  |  |   28|     34|#define SC_SUCCESS				0
  ------------------
 1731|     40|	}
 1732|       |
 1733|     21|	return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     21|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1734|     62|}
card-starcos.c:starcos_compute_signature:
 1739|    294|{
 1740|    294|	int r;
 1741|    294|	sc_apdu_t apdu;
 1742|    294|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1743|    294|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1744|    294|	starcos_ex_data *ex_data = (starcos_ex_data *)card->drv_data;
 1745|       |
 1746|    294|	if (datalen > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|    294|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (1746:6): [True: 19, False: 275]
  ------------------
 1747|     19|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1748|       |
 1749|    275|	if (ex_data->sec_ops == SC_SEC_OPERATION_SIGN) {
  ------------------
  |  |   57|    275|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1749:6): [True: 241, False: 34]
  ------------------
 1750|       |		/* compute signature with the COMPUTE SIGNATURE command */
 1751|       |
 1752|    241|		if ( IS_V3x(card) ) {
  ------------------
  |  |  121|    482|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    241|#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: 143, False: 98]
  |  |  |  |  |  Branch (119:65): [True: 98, 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|    241|			size_t tmp_len;
 1754|       |
 1755|    241|			sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A,
  ------------------
  |  |  303|    241|#define SC_APDU_CASE_4			0x24
  ------------------
 1756|    241|					   0x9E, 0x9A);
 1757|    241|			apdu.resp = out;
 1758|    241|			apdu.resplen = outlen;
 1759|    241|			apdu.le = outlen;
 1760|    241|			if (ex_data->fix_digestInfo) {
  ------------------
  |  Branch (1760:8): [True: 180, False: 61]
  ------------------
 1761|       |				// need to pad data
 1762|    180|				unsigned int flags = ex_data->fix_digestInfo & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  151|    180|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
 1763|    180|				if (flags == 0x00) {
  ------------------
  |  Branch (1763:9): [True: 180, False: 0]
  ------------------
 1764|    180|					flags = SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|    180|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 1765|    180|				}
 1766|    180|				tmp_len = sizeof(sbuf);
 1767|    180|				if (ex_data->fix_digestInfo & SC_ALGORITHM_RSA_PAD_PSS) {
  ------------------
  |  |  116|    180|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1767:9): [True: 180, False: 0]
  ------------------
 1768|    180|					r = sc_pkcs1_strip_digest_info_prefix(NULL, data, datalen, sbuf, &tmp_len);
 1769|    180|				} else {
 1770|      0|					r = sc_pkcs1_encode(card->ctx, flags, data, datalen, sbuf, &tmp_len, sizeof(sbuf)*8, NULL);
 1771|      0|				}
 1772|    180|				LOG_TEST_RET(card->ctx, r, "sc_pkcs1_encode failed");
  ------------------
  |  |  174|    180|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    180|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    180|	int _ret = (r); \
  |  |  |  |  168|    180|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 67, False: 113]
  |  |  |  |  ------------------
  |  |  |  |  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|    180|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 113]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1773|    180|			} else {
 1774|     61|				memcpy(sbuf, data, datalen);
 1775|     61|				tmp_len = datalen;
 1776|     61|			}
 1777|       |
 1778|    174|			apdu.data = sbuf;
 1779|    174|			apdu.datalen = tmp_len;
 1780|    174|			apdu.lc = tmp_len;
 1781|       |
 1782|    174|			r = sc_transmit_apdu(card, &apdu);
 1783|    174|			LOG_TEST_RET(card->ctx, r, "APDU transmit 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: 79, False: 95]
  |  |  |  |  ------------------
  |  |  |  |  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|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 95]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1784|    174|		} 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|     95|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1813:7): [True: 75, False: 20]
  |  Branch (1813:27): [True: 57, False: 18]
  ------------------
 1814|     57|			size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1814:17): [True: 0, False: 57]
  ------------------
 1815|     57|			if ( out != apdu.resp ) {
  ------------------
  |  Branch (1815:9): [True: 0, False: 57]
  ------------------
 1816|      0|				memcpy(out, apdu.resp, len);
 1817|      0|			}
 1818|     57|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)len);
  ------------------
  |  |  153|     57|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     57|	int _ret = r; \
  |  |  155|     57|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 21, False: 36]
  |  |  ------------------
  |  |  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|     36|	} else { \
  |  |  159|     36|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|     36|			"returning with: %d\n", _ret); \
  |  |  161|     36|	} \
  |  |  162|     57|	return _ret; \
  |  |  163|     57|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1819|     57|		}
 1820|     95|	} else if (ex_data->sec_ops == SC_SEC_OPERATION_AUTHENTICATE) {
  ------------------
  |  |   58|     34|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (1820:13): [True: 34, False: 0]
  ------------------
 1821|     34|		size_t tmp_len;
 1822|     34|		CHECK_NOT_SUPPORTED_V3_4(card);
  ------------------
  |  |  110|     34|	do { \
  |  |  111|     34|		if ((card)->type == SC_CARD_TYPE_STARCOS_V3_4) { \
  |  |  ------------------
  |  |  |  Branch (111:7): [True: 0, False: 34]
  |  |  ------------------
  |  |  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|     34|	} while (0);
  |  |  ------------------
  |  |  |  Branch (116:11): [Folded, False: 34]
  |  |  ------------------
  ------------------
 1823|       |		/* call INTERNAL AUTHENTICATE */
 1824|     34|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x88, 0x10, 0x00);
  ------------------
  |  |  294|     34|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1825|       |		/* fix/create DigestInfo structure (if necessary) */
 1826|     34|		if (ex_data->fix_digestInfo) {
  ------------------
  |  Branch (1826:7): [True: 34, False: 0]
  ------------------
 1827|     34|			unsigned int flags = ex_data->fix_digestInfo & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  151|     34|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
 1828|     34|			if (flags == 0x0)
  ------------------
  |  Branch (1828:8): [True: 34, False: 0]
  ------------------
 1829|       |				/* XXX: assume no hash is wanted */
 1830|     34|				flags = SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|     34|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 1831|     34|			tmp_len = sizeof(sbuf);
 1832|     34|			r = sc_pkcs1_encode(card->ctx, flags, data, datalen,
 1833|     34|					sbuf, &tmp_len, sizeof(sbuf)*8, NULL);
 1834|     34|			if (r < 0)
  ------------------
  |  Branch (1834:8): [True: 0, False: 34]
  ------------------
 1835|      0|				return r;
 1836|     34|		} else {
 1837|      0|			memcpy(sbuf, data, datalen);
 1838|      0|			tmp_len = datalen;
 1839|      0|		}
 1840|     34|		apdu.lc = tmp_len;
 1841|     34|		apdu.data = sbuf;
 1842|     34|		apdu.datalen = tmp_len;
 1843|     34|		apdu.resp = rbuf;
 1844|     34|		apdu.resplen = sizeof(rbuf);
 1845|     34|		apdu.le = 256;
 1846|     34|		r = sc_transmit_apdu(card, &apdu);
 1847|     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: 5, False: 29]
  |  |  |  |  ------------------
  |  |  |  |  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|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 29]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1848|     29|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1848:7): [True: 20, False: 9]
  |  Branch (1848:27): [True: 17, False: 3]
  ------------------
 1849|     17|			size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1849:17): [True: 0, False: 17]
  ------------------
 1850|       |
 1851|     17|			memcpy(out, apdu.resp, len);
 1852|     17|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)len);
  ------------------
  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     17|	int _ret = r; \
  |  |  155|     17|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 4, False: 13]
  |  |  ------------------
  |  |  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|     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|     17|	return _ret; \
  |  |  163|     17|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1853|     17|		}
 1854|     29|	} 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|     53|{
 1868|     53|	int r;
 1869|     53|	size_t card_max_send_size = card->max_send_size;
 1870|     53|	size_t reader_max_send_size = card->reader->max_send_size;
 1871|     53|	size_t card_max_recv_size = card->max_recv_size;
 1872|     53|	size_t reader_max_recv_size = card->reader->max_recv_size;
 1873|       |
 1874|     53|	if (sc_get_max_send_size(card) < crgram_len + 1) {
  ------------------
  |  Branch (1874:6): [True: 8, False: 45]
  ------------------
 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|      8|		card->max_send_size = crgram_len + 1;
 1879|      8|		card->reader->max_send_size = crgram_len + 1;
 1880|      8|	}
 1881|       |
 1882|     53|	if (sc_get_max_recv_size(card) < outlen) {
  ------------------
  |  Branch (1882:6): [True: 52, 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|     52|		if (0 == (card->caps & SC_CARD_CAP_APDU_EXT)
  ------------------
  |  |  554|     52|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (1886:7): [True: 36, False: 16]
  ------------------
 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|     16|			card->max_recv_size = outlen;
 1892|     16|			card->reader->max_recv_size = outlen;
 1893|     16|		}
 1894|     52|	}
 1895|       |
 1896|     53|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|    106|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|     53|#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: 13, False: 40]
  |  |  |  |  |  Branch (119:65): [True: 13, False: 27]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|     27|#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: 27]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 27]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1897|     26|		sc_apdu_t apdu;
 1898|       |
 1899|     26|		u8 *sbuf = malloc(crgram_len + 1);
 1900|     26|		if (sbuf == NULL)
  ------------------
  |  Branch (1900:7): [True: 0, False: 26]
  ------------------
 1901|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1902|       |
 1903|     26|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x80, 0x86);
  ------------------
  |  |  303|     26|#define SC_APDU_CASE_4			0x24
  ------------------
 1904|     26|		apdu.resp    = out;
 1905|     26|		apdu.resplen = outlen;
 1906|     26|		apdu.le      = outlen;
 1907|       |
 1908|     26|		sbuf[0] = 0x81;
 1909|     26|		memcpy(sbuf + 1, crgram, crgram_len);
 1910|     26|		apdu.data = sbuf;
 1911|     26|		apdu.lc = crgram_len + 1;
 1912|     26|		apdu.datalen = crgram_len + 1;
 1913|       |
 1914|     26|		r = sc_transmit_apdu(card, &apdu);
 1915|     26|		sc_mem_clear(sbuf, crgram_len + 1);
 1916|       |
 1917|     26|		free(sbuf);
 1918|       |
 1919|     26|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     26|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     26|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     26|	int _ret = (r); \
  |  |  |  |  168|     26|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1920|       |
 1921|     14|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1921:7): [True: 7, False: 7]
  |  Branch (1921:27): [True: 5, False: 2]
  ------------------
 1922|      5|			r = (int)apdu.resplen;
 1923|      9|		else
 1924|      9|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1925|     27|	} else {
 1926|     27|		r = iso_ops->decipher(card, crgram, crgram_len, out, outlen);
 1927|     27|	}
 1928|       |
 1929|       |	/* reset whatever we've modified above */
 1930|     41|	card->max_send_size = card_max_send_size;
 1931|     41|	card->reader->max_send_size = reader_max_send_size;
 1932|     41|	card->max_recv_size = card_max_recv_size;
 1933|     41|	card->reader->max_recv_size = reader_max_recv_size;
 1934|       |
 1935|     41|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     41|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     41|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     41|	int _ret = r; \
  |  |  |  |  155|     41|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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|      9|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      9|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      9|	} \
  |  |  |  |  162|     41|	return _ret; \
  |  |  |  |  163|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1936|     41|}
card-starcos.c:starcos_card_ctl:
 2014|    329|{
 2015|    329|	sc_starcos_create_data *tmp;
 2016|       |
 2017|    329|	switch (cmd)
 2018|    329|	{
 2019|      0|	case SC_CARDCTL_STARCOS_CREATE_FILE:
  ------------------
  |  Branch (2019:2): [True: 0, False: 329]
  ------------------
 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: 329]
  ------------------
 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: 329]
  ------------------
 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: 329]
  ------------------
 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: 329]
  ------------------
 2036|      0|		return starcos_erase_card(card);
 2037|    329|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2037:2): [True: 329, False: 0]
  ------------------
 2038|    329|		return starcos_get_serialnr(card, (sc_serial_number_t *)ptr);
 2039|      0|	default:
  ------------------
  |  Branch (2039:2): [True: 0, False: 329]
  ------------------
 2040|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2041|    329|	}
 2042|    329|}
card-starcos.c:starcos_get_serialnr:
 1968|    329|{
 1969|    329|	int r;
 1970|    329|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1971|    329|	sc_apdu_t apdu;
 1972|       |
 1973|    329|	if (!serial)
  ------------------
  |  Branch (1973:6): [True: 0, False: 329]
  ------------------
 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|    329|	if (card->serialnr.len) {
  ------------------
  |  Branch (1977:6): [True: 2, False: 327]
  ------------------
 1978|      2|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1979|      2|		return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 1980|      2|	}
 1981|       |
 1982|    327|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|    654|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    327|#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: 80, False: 247]
  |  |  |  |  |  Branch (119:65): [True: 149, False: 98]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|     98|#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: 97]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 97]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1983|    230|		card->serialnr.len = SC_MAX_SERIALNR;
  ------------------
  |  |  372|    230|#define SC_MAX_SERIALNR         32
  ------------------
 1984|    230|		r = sc_parse_ef_gdo(card, card->serialnr.value, &card->serialnr.len, NULL, 0);
 1985|    230|		if (r < 0) {
  ------------------
  |  Branch (1985:7): [True: 166, False: 64]
  ------------------
 1986|    166|			card->serialnr.len = 0;
 1987|    166|			return r;
 1988|    166|		}
 1989|    230|	} else {
 1990|       |		/* get serial number via GET CARD DATA */
 1991|     97|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xf6, 0x00, 0x00);
  ------------------
  |  |  292|     97|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1992|     97|		apdu.cla |= 0x80;
 1993|     97|		apdu.resp = rbuf;
 1994|     97|		apdu.resplen = sizeof(rbuf);
 1995|     97|		apdu.le   = 256;
 1996|     97|		apdu.lc   = 0;
 1997|     97|		apdu.datalen = 0;
 1998|     97|		r = sc_transmit_apdu(card, &apdu);
 1999|     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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2000|     94|		if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (2000:7): [True: 6, False: 88]
  |  Branch (2000:27): [True: 4, False: 84]
  ------------------
 2001|     10|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     10|#define SC_ERROR_INTERNAL			-1400
  ------------------
 2002|       |		/* cache serial number */
 2003|     84|		memcpy(card->serialnr.value, apdu.resp, MIN(apdu.resplen, SC_MAX_SERIALNR));
  ------------------
  |  |   70|     84|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 82, False: 2]
  |  |  ------------------
  ------------------
 2004|     84|		card->serialnr.len = MIN(apdu.resplen, SC_MAX_SERIALNR);
  ------------------
  |  |   70|     84|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 82, False: 2]
  |  |  ------------------
  ------------------
 2005|     84|	}
 2006|       |
 2007|       |	/* copy and return serial number */
 2008|    148|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2009|       |
 2010|    148|	return SC_SUCCESS;
  ------------------
  |  |   28|    148|#define SC_SUCCESS				0
  ------------------
 2011|    327|}
card-starcos.c:starcos_pin_cmd:
 2079|    677|{
 2080|    677|	int r;
 2081|       |
 2082|    677|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    677|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    677|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    677|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    677|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 677]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2083|    677|	starcos_ex_data * ex_data = (starcos_ex_data*)card->drv_data;
 2084|    677|	if ( IS_V3x(card) ) {
  ------------------
  |  |  121|  1.35k|#define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  119|    677|#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: 244, False: 433]
  |  |  |  |  |  Branch (119:65): [True: 402, False: 31]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |               #define IS_V3x(card) IS_V34(card) || IS_V35(card)
  |  |  ------------------
  |  |  |  |  120|     31|#define IS_V35(card) card->type == SC_CARD_TYPE_STARCOS_V3_5 || card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (120:22): [True: 1, False: 30]
  |  |  |  |  |  Branch (120:65): [True: 0, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2085|    647|		data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|    647|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 2086|    647|		data->pin1.encoding = ex_data->pin_encoding;
 2087|    647|	}
 2088|    677|	r = iso_ops->pin_cmd(card, data);
 2089|    677|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    677|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    677|	int _ret = r; \
  |  |  155|    677|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 677, False: 0]
  |  |  ------------------
  |  |  156|    677|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    377|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 377, False: 300]
  |  |  ------------------
  |  |  157|    677|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    677|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    677|	return _ret; \
  |  |  163|    677|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 2090|    677|}

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

sc_check_sw:
   45|   553k|{
   46|   553k|	if (card == NULL)
  ------------------
  |  Branch (46:6): [True: 0, False: 553k]
  ------------------
   47|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   48|   553k|	if (card->ops->check_sw == NULL)
  ------------------
  |  Branch (48:6): [True: 0, False: 553k]
  ------------------
   49|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
   50|   553k|	return card->ops->check_sw(card, sw1, sw2);
   51|   553k|}
sc_format_apdu:
   55|   615k|{
   56|   615k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (56:6): [True: 0, False: 615k]
  |  Branch (56:22): [True: 0, False: 615k]
  ------------------
   57|      0|		return;
   58|      0|	}
   59|   615k|	memset(apdu, 0, sizeof(*apdu));
   60|   615k|	apdu->cla = (u8) card->cla;
   61|   615k|	apdu->cse = cse;
   62|   615k|	apdu->ins = (u8) ins;
   63|   615k|	apdu->p1 = (u8) p1;
   64|   615k|	apdu->p2 = (u8) p2;
   65|   615k|}
sc_format_apdu_cse_lc_le:
   68|  9.60k|{
   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.60k|	if (!apdu)
  ------------------
  |  Branch (73:6): [True: 0, False: 9.60k]
  ------------------
   74|      0|		return;
   75|  9.60k|	if (apdu->datalen > SC_MAX_APDU_DATA_SIZE
  ------------------
  |  |   35|  19.2k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (75:6): [True: 253, False: 9.35k]
  ------------------
   76|  9.35k|			|| apdu->resplen > SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|  9.35k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (76:7): [True: 649, False: 8.70k]
  ------------------
   77|       |		/* extended length  or data chaining and/or get response */
   78|    902|		if (apdu->datalen <= SC_MAX_EXT_APDU_DATA_SIZE)
  ------------------
  |  |   38|    902|#define SC_MAX_EXT_APDU_DATA_SIZE		0xFFFF
  ------------------
  |  Branch (78:7): [True: 902, False: 0]
  ------------------
   79|    902|			apdu->lc = apdu->datalen;
   80|    902|		if (apdu->resplen <= SC_MAX_EXT_APDU_RESP_SIZE)
  ------------------
  |  |   39|    902|#define SC_MAX_EXT_APDU_RESP_SIZE		(0xFFFF+1)
  ------------------
  |  Branch (80:7): [True: 902, False: 0]
  ------------------
   81|    902|			apdu->le = apdu->resplen;
   82|    902|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (82:7): [True: 902, False: 0]
  |  Branch (82:24): [True: 382, False: 520]
  ------------------
   83|    382|			apdu->cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    382|#define SC_APDU_CASE_2			0x22
  ------------------
   84|    902|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (84:7): [True: 0, False: 902]
  |  Branch (84:25): [True: 0, False: 0]
  ------------------
   85|      0|			apdu->cse = SC_APDU_CASE_3;
  ------------------
  |  |  302|      0|#define SC_APDU_CASE_3			0x23
  ------------------
   86|    902|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (86:7): [True: 902, False: 0]
  |  Branch (86:24): [True: 520, False: 382]
  ------------------
   87|    520|			apdu->cse = SC_APDU_CASE_4;
  ------------------
  |  |  303|    520|#define SC_APDU_CASE_4			0x24
  ------------------
   88|  8.70k|	} else {
   89|       |		/* short length */
   90|  8.70k|		if (apdu->datalen <= SC_MAX_APDU_DATA_SIZE)
  ------------------
  |  |   35|  8.70k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (90:7): [True: 8.70k, False: 0]
  ------------------
   91|  8.70k|			apdu->lc = apdu->datalen;
   92|  8.70k|		if (apdu->resplen <= SC_MAX_APDU_RESP_SIZE)
  ------------------
  |  |   36|  8.70k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (92:7): [True: 8.70k, False: 0]
  ------------------
   93|  8.70k|			apdu->le = apdu->resplen;
   94|  8.70k|		if (!apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (94:7): [True: 2.66k, False: 6.03k]
  |  Branch (94:25): [True: 3, False: 2.66k]
  ------------------
   95|      3|			apdu->cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      3|#define SC_APDU_CASE_1			0x01
  ------------------
   96|  8.70k|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (96:7): [True: 6.03k, False: 2.66k]
  |  Branch (96:24): [True: 3.31k, False: 2.71k]
  ------------------
   97|  3.31k|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  3.31k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   98|  8.70k|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (98:7): [True: 2.66k, False: 6.03k]
  |  Branch (98:25): [True: 2.66k, False: 3]
  ------------------
   99|  2.66k|			apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  2.66k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  100|  8.70k|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (100:7): [True: 6.03k, False: 2.66k]
  |  Branch (100:24): [True: 2.71k, False: 3.31k]
  ------------------
  101|  2.71k|			apdu->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  2.71k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  102|  8.70k|	}
  103|  9.60k|}
sc_format_apdu_ex:
  109|  9.60k|{
  110|  9.60k|	if (!apdu) {
  ------------------
  |  Branch (110:6): [True: 0, False: 9.60k]
  ------------------
  111|      0|		return;
  112|      0|	}
  113|       |
  114|  9.60k|	memset(apdu, 0, sizeof(*apdu));
  115|  9.60k|	apdu->cla = cla;
  116|  9.60k|	apdu->ins = ins;
  117|  9.60k|	apdu->p1 = p1;
  118|  9.60k|	apdu->p2 = p2;
  119|  9.60k|	apdu->resp = resp;
  120|  9.60k|	apdu->resplen = resplen;
  121|  9.60k|	apdu->data = data;
  122|  9.60k|	apdu->datalen = datalen;
  123|  9.60k|	sc_format_apdu_cse_lc_le(apdu);
  124|  9.60k|}
sc_get_max_recv_size:
  188|   485k|{
  189|   485k|	size_t max_recv_size;
  190|   485k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (190:6): [True: 0, False: 485k]
  |  Branch (190:22): [True: 0, False: 485k]
  ------------------
  191|      0|		return 0;
  192|      0|	}
  193|   485k|	max_recv_size = card->max_recv_size;
  194|       |
  195|       |	/* initialize max_recv_size to a meaningful value */
  196|   485k|	if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  554|   485k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (196:6): [True: 55.6k, False: 430k]
  ------------------
  197|  55.6k|		if (!max_recv_size)
  ------------------
  |  Branch (197:7): [True: 2.33k, False: 53.3k]
  ------------------
  198|  2.33k|			max_recv_size = 65536;
  199|   430k|	} else {
  200|   430k|		if (!max_recv_size)
  ------------------
  |  Branch (200:7): [True: 155k, False: 274k]
  ------------------
  201|   155k|			max_recv_size = 256;
  202|   430k|	}
  203|       |
  204|       |	/*  Override card limitations with reader limitations. */
  205|   485k|	if (card->reader->max_recv_size != 0
  ------------------
  |  Branch (205:6): [True: 8.82k, False: 477k]
  ------------------
  206|  8.82k|			&& (card->reader->max_recv_size < card->max_recv_size))
  ------------------
  |  Branch (206:7): [True: 0, False: 8.82k]
  ------------------
  207|      0|		max_recv_size = card->reader->max_recv_size;
  208|       |
  209|   485k|	return max_recv_size;
  210|   485k|}
sc_get_max_send_size:
  213|   101k|{
  214|   101k|	size_t max_send_size;
  215|       |
  216|   101k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (216:6): [True: 0, False: 101k]
  |  Branch (216:22): [True: 0, False: 101k]
  ------------------
  217|      0|		return 0;
  218|      0|	}
  219|       |
  220|   101k|	max_send_size = card->max_send_size;
  221|       |
  222|       |	/* initialize max_send_size to a meaningful value */
  223|   101k|	if (card->caps & SC_CARD_CAP_APDU_EXT
  ------------------
  |  |  554|   203k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (223:6): [True: 31.5k, False: 70.2k]
  ------------------
  224|  31.5k|			&& card->reader->active_protocol != SC_PROTO_T0) {
  ------------------
  |  |  359|  31.5k|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (224:7): [True: 31.5k, False: 0]
  ------------------
  225|  31.5k|		if (!max_send_size)
  ------------------
  |  Branch (225:7): [True: 1.64k, False: 29.8k]
  ------------------
  226|  1.64k|			max_send_size = 65535;
  227|  70.2k|	} else {
  228|  70.2k|		if (!max_send_size)
  ------------------
  |  Branch (228:7): [True: 14.4k, False: 55.7k]
  ------------------
  229|  14.4k|			max_send_size = 255;
  230|  70.2k|	}
  231|       |
  232|       |	/*  Override card limitations with reader limitations. */
  233|   101k|	if (card->reader->max_send_size != 0
  ------------------
  |  Branch (233:6): [True: 5, False: 101k]
  ------------------
  234|      5|			&& (card->reader->max_send_size < card->max_send_size))
  ------------------
  |  Branch (234:7): [True: 0, False: 5]
  ------------------
  235|      0|		max_send_size = card->reader->max_send_size;
  236|       |
  237|   101k|	return max_send_size;
  238|   101k|}
sc_connect_card:
  241|  16.4k|{
  242|  16.4k|	sc_card_t *card;
  243|  16.4k|	sc_context_t *ctx;
  244|  16.4k|	struct sc_card_driver *driver;
  245|  16.4k|	int i, r = 0, idx, connected = 0;
  246|       |
  247|  16.4k|	if (card_out == NULL || reader == NULL)
  ------------------
  |  Branch (247:6): [True: 0, False: 16.4k]
  |  Branch (247:26): [True: 0, False: 16.4k]
  ------------------
  248|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  249|  16.4k|	ctx = reader->ctx;
  250|  16.4k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  16.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  16.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  16.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 16.4k]
  |  |  ------------------
  ------------------
  251|  16.4k|	if (reader->ops->connect == NULL)
  ------------------
  |  Branch (251:6): [True: 0, False: 16.4k]
  ------------------
  252|  16.4k|		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|  16.4k|	card = sc_card_new(ctx);
  255|  16.4k|	if (card == NULL)
  ------------------
  |  Branch (255:6): [True: 0, False: 16.4k]
  ------------------
  256|  16.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|  16.4k|	r = reader->ops->connect(reader);
  258|  16.4k|	if (r)
  ------------------
  |  Branch (258:6): [True: 0, False: 16.4k]
  ------------------
  259|      0|		goto err;
  260|       |
  261|  16.4k|	connected = 1;
  262|  16.4k|	card->reader = reader;
  263|  16.4k|	card->ctx = ctx;
  264|       |
  265|  16.4k|	if (reader->flags & SC_READER_ENABLE_ESCAPE)
  ------------------
  |  |  379|  16.4k|#define SC_READER_ENABLE_ESCAPE		0x00000040
  ------------------
  |  Branch (265:6): [True: 0, False: 16.4k]
  ------------------
  266|      0|		sc_detect_escape_cmds(reader);
  267|       |
  268|  16.4k|	memcpy(&card->atr, &reader->atr, sizeof(card->atr));
  269|  16.4k|	memcpy(&card->uid, &reader->uid, sizeof(card->uid));
  270|       |
  271|  16.4k|	_sc_parse_atr(reader);
  272|       |
  273|       |	/* See if the ATR matches any ATR specified in the config file */
  274|  16.4k|	if ((driver = ctx->forced_driver) == NULL) {
  ------------------
  |  Branch (274:6): [True: 16.4k, False: 0]
  ------------------
  275|  16.4k|		sc_log(ctx, "matching configured ATRs");
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
  276|   740k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (276:15): [True: 724k, False: 16.4k]
  ------------------
  277|   724k|			driver = ctx->card_drivers[i];
  278|       |
  279|   724k|			if (driver->atr_map == NULL ||
  ------------------
  |  Branch (279:8): [True: 724k, False: 0]
  ------------------
  280|   724k|			    !strcmp(driver->short_name, "default")) {
  ------------------
  |  Branch (280:8): [True: 0, False: 0]
  ------------------
  281|   724k|				driver = NULL;
  282|   724k|				continue;
  283|   724k|			}
  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|  16.4k|	}
  299|       |
  300|  16.4k|	if (driver != NULL) {
  ------------------
  |  Branch (300:6): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	else {
  318|  16.4k|		sc_card_t uninitialized = *card;
  319|  16.4k|		sc_log(ctx, "matching built-in ATRs");
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
  320|   389k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (320:15): [True: 387k, False: 2.17k]
  ------------------
  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|   387k|			*card = uninitialized;
  333|       |
  334|   387k|			struct sc_card_driver *drv = ctx->card_drivers[i];
  335|   387k|			const struct sc_card_operations *ops = drv->ops;
  336|       |
  337|   387k|			sc_log(ctx, "trying driver '%s'", drv->short_name);
  ------------------
  |  |   71|   387k|#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|   387k|			if (ops == NULL || ops->match_card == NULL)   {
  ------------------
  |  Branch (338:8): [True: 0, False: 387k]
  |  Branch (338:23): [True: 0, False: 387k]
  ------------------
  339|      0|				continue;
  340|      0|			}
  341|   387k|			else if (!(ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER)
  ------------------
  |  |  867|   387k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  |  Branch (341:13): [True: 387k, False: 0]
  ------------------
  342|   387k|				   	&& !strcmp("default", drv->short_name))   {
  ------------------
  |  Branch (342:12): [True: 2.17k, False: 385k]
  ------------------
  343|  2.17k|				sc_log(ctx , "ignore 'default' card driver");
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  344|  2.17k|				continue;
  345|  2.17k|			}
  346|       |
  347|       |			/* Needed if match_card() needs to talk with the card (e.g. card-muscle) */
  348|   385k|			*card->ops = *ops;
  349|   385k|			if (ops->match_card(card) != 1)
  ------------------
  |  Branch (349:8): [True: 370k, False: 15.2k]
  ------------------
  350|   370k|				continue;
  351|  15.2k|			sc_log(ctx, "matched: %s", drv->name);
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  352|  15.2k|			memcpy(card->ops, ops, sizeof(struct sc_card_operations));
  353|  15.2k|			card->driver = drv;
  354|  15.2k|			r = ops->init(card);
  355|  15.2k|			if (r) {
  ------------------
  |  Branch (355:8): [True: 1.69k, False: 13.5k]
  ------------------
  356|  1.69k|				sc_log(ctx, "driver '%s' init() failed: %s", drv->name, sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  357|  1.69k|				if (r == SC_ERROR_INVALID_CARD) {
  ------------------
  |  |   60|  1.69k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  |  Branch (357:9): [True: 927, False: 769]
  ------------------
  358|    927|					card->driver = NULL;
  359|    927|					continue;
  360|    927|				}
  361|    769|				goto err;
  362|  1.69k|			}
  363|  13.5k|			break;
  364|  15.2k|		}
  365|  16.4k|	}
  366|  15.6k|	if (card->driver == NULL) {
  ------------------
  |  Branch (366:6): [True: 2.17k, False: 13.5k]
  ------------------
  367|  2.17k|		sc_log(ctx, "unable to find driver for inserted card");
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  368|  2.17k|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  2.17k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  369|  2.17k|		goto err;
  370|  2.17k|	}
  371|  13.5k|	if (card->name == NULL)
  ------------------
  |  Branch (371:6): [True: 2.92k, False: 10.5k]
  ------------------
  372|  2.92k|		card->name = card->driver->name;
  373|       |
  374|       |	/* initialize max_send_size/max_recv_size to a meaningful value */
  375|  13.5k|	card->max_recv_size = sc_get_max_recv_size(card);
  376|  13.5k|	card->max_send_size = sc_get_max_send_size(card);
  377|       |
  378|  13.5k|	sc_log(ctx,
  ------------------
  |  |   71|  13.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|  13.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|  13.5k|	       card->name, card->type, card->flags, card->max_send_size,
  381|  13.5k|	       card->max_recv_size);
  382|       |
  383|  13.5k|#ifdef ENABLE_SM
  384|       |        /* Check, if secure messaging module present. */
  385|  13.5k|	r = sc_card_sm_check(card);
  386|  13.5k|	if (r)   {
  ------------------
  |  Branch (386:6): [True: 0, False: 13.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|  13.5k|#endif
  391|  13.5k|	*card_out = card;
  392|       |
  393|  13.5k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  13.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13.5k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|  2.94k|err:
  395|  2.94k|	if (connected)
  ------------------
  |  Branch (395:6): [True: 2.94k, False: 0]
  ------------------
  396|  2.94k|		reader->ops->disconnect(reader);
  397|  2.94k|	if (card != NULL)
  ------------------
  |  Branch (397:6): [True: 2.94k, False: 0]
  ------------------
  398|  2.94k|		sc_card_free(card);
  399|  2.94k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  2.94k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.94k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.94k|	int _ret = r; \
  |  |  |  |  155|  2.94k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.94k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|  2.94k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.94k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.94k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.94k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.94k|	return _ret; \
  |  |  |  |  163|  2.94k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  400|  2.94k|}
sc_disconnect_card:
  403|  16.4k|{
  404|  16.4k|	sc_context_t *ctx;
  405|       |
  406|  16.4k|	if (!card)
  ------------------
  |  Branch (406:6): [True: 2.94k, False: 13.5k]
  ------------------
  407|  2.94k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  2.94k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  408|       |
  409|  13.5k|	ctx = card->ctx;
  410|  13.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  13.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  13.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  13.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  13.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  411|       |
  412|  13.5k|	if (card->ops->finish) {
  ------------------
  |  Branch (412:6): [True: 12.6k, False: 916]
  ------------------
  413|  12.6k|		int r = card->ops->finish(card);
  414|  12.6k|		if (r)
  ------------------
  |  Branch (414:7): [True: 514, False: 12.0k]
  ------------------
  415|    514|			sc_log(ctx, "card driver finish() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|    514|#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|  12.6k|	}
  417|       |
  418|  13.5k|	if (card->reader->ops->disconnect) {
  ------------------
  |  Branch (418:6): [True: 13.5k, False: 0]
  ------------------
  419|  13.5k|		int r = card->reader->ops->disconnect(card->reader);
  420|  13.5k|		if (r)
  ------------------
  |  Branch (420:7): [True: 0, False: 13.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|  13.5k|	}
  423|       |
  424|  13.5k|#ifdef ENABLE_SM
  425|       |	/* release SM related resources */
  426|  13.5k|	sc_card_sm_unload(card);
  427|  13.5k|#endif
  428|       |
  429|  13.5k|	sc_card_free(card);
  430|  13.5k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  13.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13.5k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|  13.5k|}
sc_lock:
  458|   753k|{
  459|   753k|	int r = 0, r2 = 0;
  460|   753k|	int was_reset = 0;
  461|   753k|	int reader_lock_obtained  = 0;
  462|       |
  463|   753k|	if (card == NULL)
  ------------------
  |  Branch (463:6): [True: 0, False: 753k]
  ------------------
  464|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  465|       |
  466|   753k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   753k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   753k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   753k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   753k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 753k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  467|       |
  468|   753k|	r = sc_mutex_lock(card->ctx, card->mutex);
  469|   753k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   753k|#define SC_SUCCESS				0
  ------------------
  |  Branch (469:6): [True: 0, False: 753k]
  ------------------
  470|      0|		return r;
  471|   753k|	if (card->lock_count == 0) {
  ------------------
  |  Branch (471:6): [True: 290k, False: 463k]
  ------------------
  472|   290k|		if (card->reader->ops->lock != NULL) {
  ------------------
  |  Branch (472:7): [True: 290k, False: 0]
  ------------------
  473|   290k|			r = card->reader->ops->lock(card->reader);
  474|   290k|			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|   580k|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   290k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (474:11): [True: 0, False: 290k]
  |  Branch (474:39): [True: 0, False: 290k]
  ------------------
  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|   290k|			if (r == 0)
  ------------------
  |  Branch (479:8): [True: 290k, False: 0]
  ------------------
  480|   290k|				reader_lock_obtained = 1;
  481|   290k|		}
  482|   290k|	}
  483|   753k|	if (r == 0)
  ------------------
  |  Branch (483:6): [True: 753k, False: 0]
  ------------------
  484|   753k|		card->lock_count++;
  485|       |
  486|   753k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  487|   753k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   753k|#define SC_SUCCESS				0
  ------------------
  |  Branch (487:6): [True: 0, False: 753k]
  ------------------
  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|   753k|	if (r == 0 && was_reset > 0) {
  ------------------
  |  Branch (492:6): [True: 753k, False: 0]
  |  Branch (492:16): [True: 0, False: 753k]
  ------------------
  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|   753k|	if (r == 0 && reader_lock_obtained == 1  && card->ops->card_reader_lock_obtained) {
  ------------------
  |  Branch (500:6): [True: 753k, False: 0]
  |  Branch (500:16): [True: 290k, False: 463k]
  |  Branch (500:46): [True: 73.6k, False: 216k]
  ------------------
  501|  73.6k|		if (SC_SUCCESS != card->ops->card_reader_lock_obtained(card, was_reset))
  ------------------
  |  |   28|  73.6k|#define SC_SUCCESS				0
  ------------------
  |  Branch (501:7): [True: 6.02k, False: 67.5k]
  ------------------
  502|  6.02k|			sc_log(card->ctx, "card_reader_lock_obtained failed");
  ------------------
  |  |   71|  6.02k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  503|  73.6k|	}
  504|       |
  505|   753k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   753k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   753k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   753k|	int _ret = r; \
  |  |  |  |  155|   753k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 753k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   753k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 753k]
  |  |  |  |  ------------------
  |  |  |  |  157|   753k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   753k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   753k|	return _ret; \
  |  |  |  |  163|   753k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  506|   753k|}
sc_unlock:
  509|   753k|{
  510|   753k|	int r, r2;
  511|       |
  512|   753k|	if (!card)
  ------------------
  |  Branch (512:6): [True: 0, False: 753k]
  ------------------
  513|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  514|       |
  515|   753k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   753k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   753k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   753k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   753k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 753k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|       |
  517|   753k|	r = sc_mutex_lock(card->ctx, card->mutex);
  518|   753k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   753k|#define SC_SUCCESS				0
  ------------------
  |  Branch (518:6): [True: 0, False: 753k]
  ------------------
  519|   753k|		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|   753k|	if (card->lock_count < 1) {
  ------------------
  |  Branch (521:6): [True: 0, False: 753k]
  ------------------
  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|   753k|	if (--card->lock_count == 0) {
  ------------------
  |  Branch (524:6): [True: 290k, False: 463k]
  ------------------
  525|       |		/* release reader lock */
  526|   290k|		if (card->reader->ops->unlock != NULL)
  ------------------
  |  Branch (526:7): [True: 290k, False: 0]
  ------------------
  527|   290k|			r = card->reader->ops->unlock(card->reader);
  528|   290k|	}
  529|   753k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  530|   753k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   753k|#define SC_SUCCESS				0
  ------------------
  |  Branch (530:6): [True: 0, False: 753k]
  ------------------
  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|   753k|	return r;
  536|   753k|}
sc_read_binary:
  607|  13.2k|{
  608|  13.2k|	size_t max_le = sc_get_max_recv_size(card);
  609|  13.2k|	size_t todo = count;
  610|  13.2k|	int r;
  611|       |
  612|  13.2k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (612:6): [True: 0, False: 13.2k]
  |  Branch (612:22): [True: 0, False: 13.2k]
  |  Branch (612:43): [True: 0, False: 13.2k]
  ------------------
  613|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  614|      0|	}
  615|  13.2k|	sc_log(card->ctx, "called; %"SC_FORMAT_LEN_SIZE_T"u bytes at index %d",
  ------------------
  |  |   71|  13.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  616|  13.2k|	       count, idx);
  617|  13.2k|	if (count == 0)
  ------------------
  |  Branch (617:6): [True: 541, False: 12.6k]
  ------------------
  618|  13.2k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    541|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    541|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    541|	int _ret = r; \
  |  |  |  |  155|    541|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 541, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    541|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 541]
  |  |  |  |  ------------------
  |  |  |  |  157|    541|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    541|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    541|	return _ret; \
  |  |  |  |  163|    541|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|       |
  620|  12.6k|#ifdef ENABLE_SM
  621|  12.6k|	if (card->sm_ctx.ops.read_binary)   {
  ------------------
  |  Branch (621:6): [True: 293, False: 12.4k]
  ------------------
  622|    293|		r = card->sm_ctx.ops.read_binary(card, idx, buf, count);
  623|    293|		if (r)
  ------------------
  |  Branch (623:7): [True: 232, False: 61]
  ------------------
  624|    293|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    232|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    232|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    232|	int _ret = r; \
  |  |  |  |  155|    232|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 232, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    232|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    232|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 232, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    232|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    232|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    232|	return _ret; \
  |  |  |  |  163|    232|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  625|    293|	}
  626|  12.4k|#endif
  627|       |
  628|  12.4k|	if (card->ops->read_binary == NULL)
  ------------------
  |  Branch (628:6): [True: 0, False: 12.4k]
  ------------------
  629|  12.4k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  630|       |
  631|       |	/* lock the card now to avoid deselection of the file */
  632|  12.4k|	r = sc_lock(card);
  633|  12.4k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  12.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  12.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  12.4k|	int _ret = (r); \
  |  |  |  |  168|  12.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 12.4k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  12.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  634|       |
  635|  52.5k|	while (todo > 0) {
  ------------------
  |  Branch (635:9): [True: 47.8k, False: 4.74k]
  ------------------
  636|  47.8k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   70|  47.8k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 14.3k, False: 33.5k]
  |  |  ------------------
  ------------------
  637|       |
  638|  47.8k|		r = card->ops->read_binary(card, idx, buf, chunk, flags);
  639|  47.8k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  45.0k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (639:7): [True: 2.76k, False: 45.0k]
  |  Branch (639:17): [True: 239, False: 44.8k]
  ------------------
  640|  3.00k|			break;
  641|  44.8k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (641:7): [True: 4.71k, False: 40.1k]
  |  Branch (641:16): [True: 2.83k, False: 1.88k]
  ------------------
  642|       |			/* the last command failed, but previous ones succeeded.
  643|       |			 * Let's just return what we've successfully read. */
  644|  2.83k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  2.83k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  645|  2.83k|			break;
  646|  2.83k|		}
  647|  42.0k|		if (r < 0) {
  ------------------
  |  Branch (647:7): [True: 1.88k, False: 40.1k]
  ------------------
  648|  1.88k|			sc_unlock(card);
  649|  1.88k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.88k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.88k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.88k|	int _ret = r; \
  |  |  |  |  155|  1.88k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.88k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.88k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.88k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.88k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.88k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.88k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.88k|	return _ret; \
  |  |  |  |  163|  1.88k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  650|  1.88k|		}
  651|  40.1k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (651:7): [True: 0, False: 40.1k]
  |  Branch (651:40): [True: 0, False: 40.1k]
  ------------------
  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|  40.1k|		todo -= (size_t) r;
  658|  40.1k|		buf  += (size_t) r;
  659|  40.1k|		idx  += (size_t) r;
  660|  40.1k|	}
  661|       |
  662|  10.5k|	sc_unlock(card);
  663|       |
  664|  10.5k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  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: 1.18k, False: 9.39k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.18k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.18k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.18k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.39k|	} else { \
  |  |  |  |  159|  9.39k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  9.39k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  9.39k|	} \
  |  |  |  |  162|  10.5k|	return _ret; \
  |  |  |  |  163|  10.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  665|  10.5k|}
sc_select_file:
  818|   112k|{
  819|   112k|	int r;
  820|   112k|	char pbuf[SC_MAX_PATH_STRING_SIZE];
  821|       |
  822|   112k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (822:6): [True: 0, False: 112k]
  |  Branch (822:22): [True: 0, False: 112k]
  ------------------
  823|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  824|      0|	}
  825|       |
  826|   112k|	r = sc_path_print(pbuf, sizeof(pbuf), in_path);
  827|   112k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   112k|#define SC_SUCCESS				0
  ------------------
  |  Branch (827:6): [True: 665, False: 111k]
  ------------------
  828|    665|		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|   112k|	if (file != NULL)
  ------------------
  |  Branch (833:6): [True: 54.4k, False: 58.0k]
  ------------------
  834|  54.4k|		*file = NULL;
  835|       |
  836|   112k|	sc_log(card->ctx, "called; type=%d, path=%s", in_path->type, pbuf);
  ------------------
  |  |   71|   112k|#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|   112k|	if (in_path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|   112k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (837:6): [True: 0, False: 112k]
  ------------------
  838|   112k|		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|   112k|	if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|   112k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (840:6): [True: 81.8k, False: 30.6k]
  ------------------
  841|       |		/* Perform a sanity check */
  842|  81.8k|		size_t i;
  843|       |
  844|  81.8k|		if ((in_path->len & 1) != 0)
  ------------------
  |  Branch (844:7): [True: 105, False: 81.7k]
  ------------------
  845|  81.8k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    105|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    105|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    105|	int _ret = r; \
  |  |  |  |  155|    105|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 105, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    105|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    105|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 105, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    105|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    105|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    105|	return _ret; \
  |  |  |  |  163|    105|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  846|       |
  847|   245k|		for (i = 0; i < in_path->len/2; i++) {
  ------------------
  |  Branch (847:15): [True: 164k, False: 81.7k]
  ------------------
  848|   164k|			u8 p1 = in_path->value[2*i],
  849|   164k|			   p2 = in_path->value[2*i+1];
  850|       |
  851|   164k|			if ((p1 == 0x3F && p2 == 0x00) && i != 0)
  ------------------
  |  Branch (851:9): [True: 55.8k, False: 108k]
  |  Branch (851:23): [True: 55.6k, False: 156]
  |  Branch (851:38): [True: 38, False: 55.6k]
  ------------------
  852|   164k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     38|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     38|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     38|	int _ret = r; \
  |  |  |  |  155|     38|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     38|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     38|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     38|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     38|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     38|	return _ret; \
  |  |  |  |  163|     38|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  853|   164k|		}
  854|  81.7k|	}
  855|   112k|	if (card->ops->select_file == NULL)
  ------------------
  |  Branch (855:6): [True: 0, False: 112k]
  ------------------
  856|   112k|		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|   112k|	r = card->ops->select_file(card, in_path, file);
  858|   112k|	LOG_TEST_RET(card->ctx, r, "'SELECT' error");
  ------------------
  |  |  174|   112k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   112k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   112k|	int _ret = (r); \
  |  |  |  |  168|   112k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 82.5k, False: 29.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|  82.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  82.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  82.5k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  82.5k|		return _ret; \
  |  |  |  |  172|  82.5k|	} \
  |  |  |  |  173|   112k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 29.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|       |
  860|  29.8k|	if (file) {
  ------------------
  |  Branch (860:6): [True: 16.2k, False: 13.5k]
  ------------------
  861|  16.2k|		if (*file)
  ------------------
  |  Branch (861:7): [True: 16.1k, False: 106]
  ------------------
  862|       |			/* Remember file path */
  863|  16.1k|			(*file)->path = *in_path;
  864|    106|		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|    106|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    106|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  869|  16.2k|	}
  870|       |
  871|  29.8k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  29.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  29.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  29.8k|	int _ret = r; \
  |  |  |  |  155|  29.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 29.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  29.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|    106|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 106, False: 29.6k]
  |  |  |  |  ------------------
  |  |  |  |  157|  29.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  29.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|  29.8k|	return _ret; \
  |  |  |  |  163|  29.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  872|  29.8k|}
sc_get_data:
  876|  6.94k|{
  877|  6.94k|	int	r;
  878|       |
  879|  6.94k|	sc_log(card->ctx, "called, tag=%04x", tag);
  ------------------
  |  |   71|  6.94k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  880|  6.94k|	if (card->ops->get_data == NULL)
  ------------------
  |  Branch (880:6): [True: 0, False: 6.94k]
  ------------------
  881|  6.94k|		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.94k|	r = card->ops->get_data(card, tag, buf, len);
  883|       |
  884|  6.94k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  6.94k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.94k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.94k|	int _ret = r; \
  |  |  |  |  155|  6.94k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.05k, False: 1.89k]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|  3.99k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.99k, False: 1.06k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.05k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.05k|	} else { \
  |  |  |  |  159|  1.89k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.89k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.89k|	} \
  |  |  |  |  162|  6.94k|	return _ret; \
  |  |  |  |  163|  6.94k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  885|  6.94k|}
sc_read_record:
  940|   183k|{
  941|   183k|	size_t max_le = sc_get_max_recv_size(card);
  942|   183k|	size_t todo = count;
  943|   183k|	int r;
  944|       |
  945|   183k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (945:6): [True: 0, False: 183k]
  |  Branch (945:22): [True: 0, False: 183k]
  |  Branch (945:43): [True: 0, False: 183k]
  ------------------
  946|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  947|      0|	}
  948|   183k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   183k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   183k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   183k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   183k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 183k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  949|   183k|	if (count == 0)
  ------------------
  |  Branch (949:6): [True: 163k, False: 20.3k]
  ------------------
  950|   183k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|   163k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   163k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   163k|	int _ret = r; \
  |  |  |  |  155|   163k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 163k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   163k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 163k]
  |  |  |  |  ------------------
  |  |  |  |  157|   163k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   163k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   163k|	return _ret; \
  |  |  |  |  163|   163k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  951|       |
  952|  20.3k|	if (card->ops->read_record == NULL)
  ------------------
  |  Branch (952:6): [True: 16, False: 20.3k]
  ------------------
  953|  20.3k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  954|       |
  955|       |	/* lock the card now to avoid deselection of the file */
  956|  20.3k|	r = sc_lock(card);
  957|  20.3k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  20.3k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  20.3k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  20.3k|	int _ret = (r); \
  |  |  |  |  168|  20.3k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 20.3k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  20.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 20.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  958|       |
  959|  38.7k|	while (todo > 0) {
  ------------------
  |  Branch (959:9): [True: 37.5k, False: 1.20k]
  ------------------
  960|  37.5k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   70|  37.5k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 29.4k, False: 8.12k]
  |  |  ------------------
  ------------------
  961|       |
  962|  37.5k|		r = card->ops->read_record(card, rec_nr, idx, buf, chunk, flags);
  963|  37.5k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  35.4k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (963:7): [True: 2.08k, False: 35.4k]
  |  Branch (963:17): [True: 653, False: 34.8k]
  ------------------
  964|  2.74k|			break;
  965|  34.8k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (965:7): [True: 16.4k, False: 18.3k]
  |  Branch (965:16): [True: 15.2k, False: 1.16k]
  ------------------
  966|       |			/* the last command failed, but previous ones succeeded.
  967|       |			 * Let's just return what we've successfully read. */
  968|  15.2k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  969|  15.2k|			break;
  970|  15.2k|		}
  971|  19.5k|		if (r < 0) {
  ------------------
  |  Branch (971:7): [True: 1.16k, False: 18.3k]
  ------------------
  972|  1.16k|			sc_unlock(card);
  973|  1.16k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.16k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.16k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.16k|	int _ret = r; \
  |  |  |  |  155|  1.16k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.16k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.16k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.16k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.16k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.16k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.16k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.16k|	return _ret; \
  |  |  |  |  163|  1.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  974|  1.16k|		}
  975|  18.3k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (975:7): [True: 0, False: 18.3k]
  |  Branch (975:40): [True: 0, False: 18.3k]
  ------------------
  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|  18.3k|		todo -= (size_t) r;
  982|  18.3k|		buf  += (size_t) r;
  983|  18.3k|		idx  += (size_t) r;
  984|  18.3k|	}
  985|       |
  986|  19.2k|	sc_unlock(card);
  987|       |
  988|  19.2k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  19.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  19.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  19.2k|	int _ret = r; \
  |  |  |  |  155|  19.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.56k, False: 16.6k]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.56k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.56k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.56k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.6k|	} else { \
  |  |  |  |  159|  16.6k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.6k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.6k|	} \
  |  |  |  |  162|  19.2k|	return _ret; \
  |  |  |  |  163|  19.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  989|  19.2k|}
sc_card_ctl:
 1099|   129k|{
 1100|   129k|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|   129k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1101|       |
 1102|   129k|	if (card == NULL) {
  ------------------
  |  Branch (1102:6): [True: 0, False: 129k]
  ------------------
 1103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1104|      0|	}
 1105|   129k|	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called with cmd=%lu\n", cmd);
  ------------------
  |  |   70|   129k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1106|       |
 1107|   129k|	if (card->ops->card_ctl != NULL)
  ------------------
  |  Branch (1107:6): [True: 127k, False: 1.74k]
  ------------------
 1108|   127k|		r = card->ops->card_ctl(card, cmd, args);
 1109|       |
 1110|       |	/* suppress "not supported" error messages */
 1111|   129k|	if (r == SC_ERROR_NOT_SUPPORTED) {
  ------------------
  |  |   89|   129k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (1111:6): [True: 4.25k, False: 125k]
  ------------------
 1112|  4.25k|		sc_log(card->ctx, "card_ctl(%lu) not supported", cmd);
  ------------------
  |  |   71|  4.25k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1113|  4.25k|		return r;
 1114|  4.25k|	}
 1115|   125k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   125k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   125k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   125k|	int _ret = r; \
  |  |  |  |  155|   125k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 92.6k, False: 32.7k]
  |  |  |  |  ------------------
  |  |  |  |  156|  92.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|  37.9k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 37.9k, False: 54.7k]
  |  |  |  |  ------------------
  |  |  |  |  157|  92.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  92.6k|	} else { \
  |  |  |  |  159|  32.7k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  32.7k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  32.7k|	} \
  |  |  |  |  162|   125k|	return _ret; \
  |  |  |  |  163|   125k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1116|   125k|}
_sc_card_add_algorithm:
 1119|  52.3k|{
 1120|  52.3k|	sc_algorithm_info_t *p;
 1121|       |
 1122|  52.3k|	if (info == NULL) {
  ------------------
  |  Branch (1122:6): [True: 0, False: 52.3k]
  ------------------
 1123|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1124|      0|	}
 1125|  52.3k|	p = (sc_algorithm_info_t *) realloc(card->algorithms, (card->algorithm_count + 1) * sizeof(*info));
 1126|  52.3k|	if (!p) {
  ------------------
  |  Branch (1126:6): [True: 0, False: 52.3k]
  ------------------
 1127|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1128|      0|	}
 1129|  52.3k|	card->algorithms = p;
 1130|  52.3k|	p += card->algorithm_count;
 1131|  52.3k|	card->algorithm_count++;
 1132|  52.3k|	*p = *info;
 1133|  52.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  52.3k|#define SC_SUCCESS				0
  ------------------
 1134|  52.3k|}
_sc_card_add_symmetric_alg:
 1138|    109|{
 1139|    109|	sc_algorithm_info_t info;
 1140|       |
 1141|    109|	memset(&info, 0, sizeof(info));
 1142|    109|	info.algorithm = algorithm;
 1143|    109|	info.key_length = key_length;
 1144|    109|	info.flags = flags;
 1145|       |
 1146|    109|	return _sc_card_add_algorithm(card, &info);
 1147|    109|}
_sc_card_add_ec_alg:
 1184|  7.36k|{
 1185|  7.36k|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1186|  7.36k|		curve_oid, SC_ALGORITHM_EC);
  ------------------
  |  |   79|  7.36k|#define SC_ALGORITHM_EC		2
  ------------------
 1187|  7.36k|}
_sc_card_add_eddsa_alg:
 1192|    188|{
 1193|       |	/* For simplicity, share the ec union with the curve information */
 1194|    188|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1195|    188|		curve_oid, SC_ALGORITHM_EDDSA);
  ------------------
  |  |   81|    188|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1196|    188|}
_sc_card_add_xeddsa_alg:
 1201|    188|{
 1202|       |	/* For simplicity, share the ec union with the curve information */
 1203|    188|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1204|    188|		curve_oid, SC_ALGORITHM_XEDDSA);
  ------------------
  |  |   82|    188|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1205|    188|}
sc_card_find_alg:
 1209|  78.2k|{
 1210|  78.2k|	int i;
 1211|       |
 1212|   287k|	for (i = 0; i < card->algorithm_count; i++) {
  ------------------
  |  Branch (1212:14): [True: 272k, False: 14.8k]
  ------------------
 1213|   272k|		sc_algorithm_info_t *info = &card->algorithms[i];
 1214|       |
 1215|   272k|		if (param && (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   79|  1.78k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1215:7): [True: 893, False: 271k]
  |  Branch (1215:17): [True: 158, False: 735]
  ------------------
 1216|    735|			info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   81|  1.62k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1216:4): [True: 158, False: 577]
  ------------------
 1217|    577|			info->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   82|    577|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1217:4): [True: 158, False: 419]
  ------------------
 1218|    474|			if (sc_compare_oid((struct sc_object_id *)param, &info->u._ec.params.id))
  ------------------
  |  Branch (1218:8): [True: 0, False: 474]
  ------------------
 1219|      0|				return info;
 1220|   272k|		} else if (info->algorithm != algorithm) {
  ------------------
  |  Branch (1220:14): [True: 61.0k, False: 210k]
  ------------------
 1221|  61.0k|			continue;
 1222|   210k|		} else if (info->key_length == key_length)
  ------------------
  |  Branch (1222:14): [True: 63.3k, False: 147k]
  ------------------
 1223|  63.3k|			return info;
 1224|   272k|	}
 1225|  14.8k|	return NULL;
 1226|  78.2k|}
sc_card_find_ec_alg:
 1230|  6.80k|{
 1231|  6.80k|	return sc_card_find_alg(card, SC_ALGORITHM_EC, key_length, curve_name);
  ------------------
  |  |   79|  6.80k|#define SC_ALGORITHM_EC		2
  ------------------
 1232|  6.80k|}
sc_card_find_eddsa_alg:
 1236|    220|{
 1237|    220|	return sc_card_find_alg(card, SC_ALGORITHM_EDDSA, key_length, curve_name);
  ------------------
  |  |   81|    220|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1238|    220|}
_sc_card_add_rsa_alg:
 1248|  44.3k|{
 1249|  44.3k|	sc_algorithm_info_t info;
 1250|       |
 1251|  44.3k|	memset(&info, 0, sizeof(info));
 1252|  44.3k|	info.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   78|  44.3k|#define SC_ALGORITHM_RSA		0
  ------------------
 1253|  44.3k|	info.key_length = key_length;
 1254|  44.3k|	info.flags = flags;
 1255|       |	/* disable particular PKCS1 v1.5 padding type if also RAW is supported on card */
 1256|  44.3k|	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  120|  44.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  44.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|  44.3k|#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|  44.3k|#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|  44.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  44.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|  44.3k|#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|  44.3k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (1256:6): [True: 8.13k, False: 36.2k]
  ------------------
 1257|  8.13k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  118|  8.13k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1257:7): [True: 0, False: 8.13k]
  ------------------
 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.13k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)
  ------------------
  |  |  119|  8.13k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1259:7): [True: 8.13k, False: 0]
  ------------------
 1260|  8.13k|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  119|  8.13k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
 1261|  8.13k|	}
 1262|  44.3k|	info.u._rsa.exponent = exponent;
 1263|       |
 1264|  44.3k|	return _sc_card_add_algorithm(card, &info);
 1265|  44.3k|}
sc_card_find_rsa_alg:
 1268|  71.1k|{
 1269|  71.1k|	return sc_card_find_alg(card, SC_ALGORITHM_RSA, key_length, NULL);
  ------------------
  |  |   78|  71.1k|#define SC_ALGORITHM_RSA		0
  ------------------
 1270|  71.1k|}
_sc_match_atr:
 1341|   332k|{
 1342|   332k|	int res;
 1343|       |
 1344|   332k|	if (card == NULL)
  ------------------
  |  Branch (1344:6): [True: 0, False: 332k]
  ------------------
 1345|      0|		return -1;
 1346|   332k|	res = match_atr_table(card->ctx, table, &card->atr);
 1347|   332k|	if (res < 0)
  ------------------
  |  Branch (1347:6): [True: 320k, False: 11.8k]
  ------------------
 1348|   320k|		return res;
 1349|  11.8k|	if (type_out != NULL)
  ------------------
  |  Branch (1349:6): [True: 11.5k, False: 300]
  ------------------
 1350|  11.5k|		*type_out = table[res].type;
 1351|  11.8k|	return res;
 1352|   332k|}
_sc_match_atr_block:
 1355|  13.5k|{
 1356|  13.5k|	struct sc_card_driver *drv;
 1357|  13.5k|	struct sc_atr_table *table;
 1358|  13.5k|	int res;
 1359|       |
 1360|  13.5k|	if (ctx == NULL)
  ------------------
  |  Branch (1360:6): [True: 0, False: 13.5k]
  ------------------
 1361|      0|		return NULL;
 1362|  13.5k|	if (driver) {
  ------------------
  |  Branch (1362:6): [True: 13.5k, False: 0]
  ------------------
 1363|  13.5k|		drv = driver;
 1364|  13.5k|		table = drv->atr_map;
 1365|  13.5k|		res = match_atr_table(ctx, table, atr);
 1366|  13.5k|		if (res < 0)
  ------------------
  |  Branch (1366:7): [True: 13.5k, False: 0]
  ------------------
 1367|  13.5k|			return NULL;
 1368|      0|		return table[res].card_atr;
 1369|  13.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|  13.5k|}
sc_get_conf_block:
 1453|  47.4k|{
 1454|  47.4k|	int i;
 1455|  47.4k|	scconf_block *conf_block = NULL;
 1456|       |
 1457|  94.8k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (1457:14): [True: 47.4k, False: 47.4k]
  ------------------
 1458|  47.4k|		scconf_block **blocks;
 1459|       |
 1460|  47.4k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], name1, name2);
 1461|  47.4k|		if (blocks != NULL) {
  ------------------
  |  Branch (1461:7): [True: 47.4k, False: 0]
  ------------------
 1462|  47.4k|			conf_block = blocks[0];
 1463|  47.4k|			free(blocks);
 1464|  47.4k|		}
 1465|  47.4k|		if (conf_block != NULL && priority)
  ------------------
  |  Branch (1465:7): [True: 0, False: 47.4k]
  |  Branch (1465:29): [True: 0, False: 0]
  ------------------
 1466|      0|			break;
 1467|  47.4k|	}
 1468|  47.4k|	return conf_block;
 1469|  47.4k|}
sc_clear_ec_params:
 1473|  7.74k|{
 1474|  7.74k|	if (ecp) {
  ------------------
  |  Branch (1474:6): [True: 7.74k, False: 0]
  ------------------
 1475|  7.74k|		free(ecp->named_curve);
 1476|  7.74k|		free(ecp->der.value);
 1477|  7.74k|		memset(ecp, 0, sizeof(struct sc_ec_parameters));
 1478|  7.74k|	}
 1479|  7.74k|	return;
 1480|  7.74k|}
card.c:sc_card_new:
  127|  16.4k|{
  128|  16.4k|	sc_card_t *card;
  129|       |
  130|  16.4k|	if (ctx == NULL)
  ------------------
  |  Branch (130:6): [True: 0, False: 16.4k]
  ------------------
  131|      0|		return NULL;
  132|       |
  133|  16.4k|	card = calloc(1, sizeof(struct sc_card));
  134|  16.4k|	if (card == NULL)
  ------------------
  |  Branch (134:6): [True: 0, False: 16.4k]
  ------------------
  135|      0|		return NULL;
  136|  16.4k|	card->ops = malloc(sizeof(struct sc_card_operations));
  137|  16.4k|	if (card->ops == NULL) {
  ------------------
  |  Branch (137:6): [True: 0, False: 16.4k]
  ------------------
  138|      0|		free(card);
  139|      0|		return NULL;
  140|      0|	}
  141|       |
  142|  16.4k|	card->ctx = ctx;
  143|  16.4k|	if (sc_mutex_create(ctx, &card->mutex) != SC_SUCCESS) {
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (143:6): [True: 0, False: 16.4k]
  ------------------
  144|      0|		free(card->ops);
  145|      0|		free(card);
  146|      0|		return NULL;
  147|      0|	}
  148|       |
  149|  16.4k|	card->type = -1;
  150|  16.4k|	card->app_count = -1;
  151|       |
  152|  16.4k|	return card;
  153|  16.4k|}
card.c:sc_card_free:
  156|  16.4k|{
  157|  16.4k|	sc_free_apps(card);
  158|  16.4k|	sc_free_ef_atr(card);
  159|       |
  160|  16.4k|	free(card->ops);
  161|       |
  162|  16.4k|	if (card->algorithms != NULL)   {
  ------------------
  |  Branch (162:6): [True: 12.4k, False: 3.98k]
  ------------------
  163|  12.4k|		int i;
  164|  64.8k|		for (i=0; i<card->algorithm_count; i++)   {
  ------------------
  |  Branch (164:13): [True: 52.3k, False: 12.4k]
  ------------------
  165|  52.3k|			struct sc_algorithm_info *info = (card->algorithms + i);
  166|  52.3k|			if (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   79|   104k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (166:8): [True: 7.36k, False: 44.9k]
  ------------------
  167|  44.9k|					info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   81|  97.2k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (167:6): [True: 188, False: 44.7k]
  ------------------
  168|  44.7k|					info->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   82|  44.7k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (168:6): [True: 188, False: 44.5k]
  ------------------
  169|  7.74k|				sc_clear_ec_params(&info->u._ec.params);
  170|  7.74k|			}
  171|  52.3k|		}
  172|  12.4k|		free(card->algorithms);
  173|       |
  174|  12.4k|		card->algorithms = NULL;
  175|  12.4k|		card->algorithm_count = 0;
  176|  12.4k|	}
  177|       |
  178|  16.4k|	if (card->mutex != NULL) {
  ------------------
  |  Branch (178:6): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	sc_mem_clear(card, sizeof(*card));
  184|  16.4k|	free(card);
  185|  16.4k|}
card.c:_sc_card_add_ec_alg_int:
 1154|  7.74k|{
 1155|  7.74k|	sc_algorithm_info_t info;
 1156|  7.74k|	int r;
 1157|       |
 1158|  7.74k|	memset(&info, 0, sizeof(info));
 1159|  7.74k|	sc_init_oid(&info.u._ec.params.id);
 1160|       |
 1161|  7.74k|	info.algorithm = algorithm;
 1162|  7.74k|	info.key_length = key_length;
 1163|  7.74k|	info.flags = flags;
 1164|       |
 1165|  7.74k|	info.u._ec.ext_flags = ext_flags;
 1166|  7.74k|	if (curve_oid) {
  ------------------
  |  Branch (1166:6): [True: 2.87k, False: 4.86k]
  ------------------
 1167|  2.87k|		info.u._ec.params.id = *curve_oid;
 1168|  2.87k|		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.87k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_encode_oid failed");
  ------------------
  |  |  184|  2.87k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.87k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.87k|	int _ret = (r); \
  |  |  |  |  178|  2.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.87k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  2.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1170|  2.87k|		r = sc_pkcs15_fix_ec_parameters(card->ctx, &info.u._ec.params);
 1171|  2.87k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_pkcs15_fix_ec_parameters failed");
  ------------------
  |  |  184|  2.87k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.87k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.87k|	int _ret = (r); \
  |  |  |  |  178|  2.87k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.87k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  2.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1172|  2.87k|	}
 1173|       |
 1174|  7.74k|	r = _sc_card_add_algorithm(card, &info);
 1175|  7.74k|	return r;
 1176|      0|err:
 1177|      0|	sc_clear_ec_params(&info.u._ec.params);
 1178|      0|	return r;
 1179|  7.74k|}
card.c:match_atr_table:
 1278|   345k|{
 1279|   345k|	u8 *card_atr_bin;
 1280|   345k|	size_t card_atr_bin_len;
 1281|   345k|	char card_atr_hex[3 * SC_MAX_ATR_SIZE];
 1282|   345k|	size_t card_atr_hex_len;
 1283|   345k|	unsigned int i = 0;
 1284|       |
 1285|   345k|	if (ctx == NULL || table == NULL || atr == NULL)
  ------------------
  |  Branch (1285:6): [True: 0, False: 345k]
  |  Branch (1285:21): [True: 13.5k, False: 332k]
  |  Branch (1285:38): [True: 0, False: 332k]
  ------------------
 1286|  13.5k|		return -1;
 1287|   332k|	card_atr_bin = atr->value;
 1288|   332k|	card_atr_bin_len = atr->len;
 1289|   332k|	sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
 1290|   332k|	card_atr_hex_len = strlen(card_atr_hex);
 1291|       |
 1292|   332k|	sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR     : %s", card_atr_hex);
  ------------------
  |  |   70|   332k|#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.87M|	for (i = 0; table[i].atr != NULL; i++) {
  ------------------
  |  Branch (1294:14): [True: 2.55M, False: 320k]
  ------------------
 1295|  2.55M|		const char *tatr = table[i].atr;
 1296|  2.55M|		const char *matr = table[i].atrmask;
 1297|  2.55M|		size_t tatr_len = strlen(tatr);
 1298|  2.55M|		u8 mbin[SC_MAX_ATR_SIZE], tbin[SC_MAX_ATR_SIZE];
 1299|  2.55M|		size_t mbin_len, tbin_len, s, matr_len;
 1300|  2.55M|		size_t fix_hex_len = card_atr_hex_len;
 1301|  2.55M|		size_t fix_bin_len = card_atr_bin_len;
 1302|       |
 1303|  2.55M|		sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR try : %s", tatr);
  ------------------
  |  |   70|  2.55M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1304|       |
 1305|  2.55M|		if (tatr_len != fix_hex_len) {
  ------------------
  |  Branch (1305:7): [True: 2.46M, False: 95.5k]
  ------------------
 1306|  2.46M|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ignored - wrong length");
  ------------------
  |  |   70|  2.46M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1307|  2.46M|			continue;
 1308|  2.46M|		}
 1309|  95.5k|		if (matr != NULL) {
  ------------------
  |  Branch (1309:7): [True: 22.2k, False: 73.2k]
  ------------------
 1310|  22.2k|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR mask: %s", matr);
  ------------------
  |  |   70|  22.2k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1311|       |
 1312|  22.2k|			matr_len = strlen(matr);
 1313|  22.2k|			if (tatr_len != matr_len)
  ------------------
  |  Branch (1313:8): [True: 0, False: 22.2k]
  ------------------
 1314|      0|				continue;
 1315|  22.2k|			tbin_len = sizeof(tbin);
 1316|  22.2k|			sc_hex_to_bin(tatr, tbin, &tbin_len);
 1317|  22.2k|			mbin_len = sizeof(mbin);
 1318|  22.2k|			sc_hex_to_bin(matr, mbin, &mbin_len);
 1319|  22.2k|			if (mbin_len != fix_bin_len) {
  ------------------
  |  Branch (1319:8): [True: 0, False: 22.2k]
  ------------------
 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|   425k|			for (s = 0; s < tbin_len; s++) {
  ------------------
  |  Branch (1323:16): [True: 403k, False: 22.2k]
  ------------------
 1324|       |				/* reduce tatr with mask */
 1325|   403k|				tbin[s] = (tbin[s] & mbin[s]);
 1326|       |				/* create copy of card_atr_bin masked) */
 1327|   403k|				mbin[s] = (card_atr_bin[s] & mbin[s]);
 1328|   403k|			}
 1329|  22.2k|			if (memcmp(tbin, mbin, tbin_len) != 0)
  ------------------
  |  Branch (1329:8): [True: 17.7k, False: 4.52k]
  ------------------
 1330|  17.7k|				continue;
 1331|  73.2k|		} else {
 1332|  73.2k|			if (strncasecmp(tatr, card_atr_hex, tatr_len) != 0)
  ------------------
  |  Branch (1332:8): [True: 66.0k, False: 7.28k]
  ------------------
 1333|  66.0k|				continue;
 1334|  73.2k|		}
 1335|  11.8k|		return i;
 1336|  95.5k|	}
 1337|   320k|	return -1;
 1338|   332k|}
card.c:sc_card_sm_unload:
 1519|  13.5k|{
 1520|  13.5k|	if (card->sm_ctx.module.ops.module_cleanup)
  ------------------
  |  Branch (1520:6): [True: 0, False: 13.5k]
  ------------------
 1521|      0|		card->sm_ctx.module.ops.module_cleanup(card->ctx);
 1522|       |
 1523|  13.5k|	if (card->sm_ctx.module.handle)
  ------------------
  |  Branch (1523:6): [True: 0, False: 13.5k]
  ------------------
 1524|      0|		sc_dlclose(card->sm_ctx.module.handle);
 1525|       |	card->sm_ctx.module.handle = NULL;
 1526|  13.5k|	return 0;
 1527|  13.5k|}
card.c:sc_card_sm_check:
 1622|  13.5k|{
 1623|  13.5k|	const char *sm = NULL, *module_name = NULL, *module_path = NULL, *module_data = NULL, *sm_mode = NULL;
 1624|  13.5k|	struct sc_context *ctx = card->ctx;
 1625|  13.5k|	scconf_block *atrblock = NULL, *sm_conf_block = NULL;
 1626|  13.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|  13.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  13.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  13.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  13.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  13.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1635|       |
 1636|       |	/* get the name of card specific SM configuration section */
 1637|  13.5k|	atrblock = _sc_match_atr_block(ctx, card->driver, &card->atr);
 1638|  13.5k|	if (atrblock == NULL)
  ------------------
  |  Branch (1638:6): [True: 13.5k, False: 0]
  ------------------
 1639|  13.5k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  13.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13.5k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|    471|{
  255|    471|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (255:6): [True: 0, False: 471]
  |  Branch (255:20): [True: 0, False: 471]
  ------------------
  256|      0|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      0|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  257|      0|	}
  258|       |
  259|    471|	if (method == COMPRESSION_AUTO) {
  ------------------
  |  |   26|    471|#define COMPRESSION_AUTO	0
  ------------------
  |  Branch (259:6): [True: 470, False: 1]
  ------------------
  260|    470|		method = detect_method(in, inLen);
  261|    470|		if (method == COMPRESSION_UNKNOWN) {
  ------------------
  |  |   29|    470|#define COMPRESSION_UNKNOWN (-1)
  ------------------
  |  Branch (261:7): [True: 122, False: 348]
  ------------------
  262|    122|			return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|    122|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  263|    122|		}
  264|    470|	}
  265|       |
  266|    349|	switch (method) {
  267|    347|	case COMPRESSION_ZLIB:
  ------------------
  |  |   27|    347|#define COMPRESSION_ZLIB	1
  ------------------
  |  Branch (267:2): [True: 347, False: 2]
  ------------------
  268|    347|		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: 347]
  ------------------
  270|      2|		return sc_decompress_zlib_alloc(out, outLen, in, inLen, 1);
  271|      0|	default:
  ------------------
  |  Branch (271:2): [True: 0, False: 349]
  ------------------
  272|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  273|    349|	}
  274|    349|}
compression.c:zerr_to_opensc:
   34|    349|static int zerr_to_opensc(int err) {
   35|    349|	switch(err) {
   36|      0|	case Z_OK:
  ------------------
  |  Branch (36:2): [True: 0, False: 349]
  ------------------
   37|    255|	case Z_STREAM_END:
  ------------------
  |  Branch (37:2): [True: 255, False: 94]
  ------------------
   38|    255|		return SC_SUCCESS;
  ------------------
  |  |   28|    255|#define SC_SUCCESS				0
  ------------------
   39|     10|	case Z_UNKNOWN:
  ------------------
  |  Branch (39:2): [True: 10, False: 339]
  ------------------
   40|     10|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     10|#define SC_ERROR_UNKNOWN			-1900
  ------------------
   41|     64|	case Z_DATA_ERROR:
  ------------------
  |  Branch (41:2): [True: 64, False: 285]
  ------------------
   42|     84|	case Z_BUF_ERROR:
  ------------------
  |  Branch (42:2): [True: 20, False: 329]
  ------------------
   43|     84|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     84|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
   44|      0|	case Z_MEM_ERROR:
  ------------------
  |  Branch (44:2): [True: 0, False: 349]
  ------------------
   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: 349]
  ------------------
   47|      0|	case Z_STREAM_ERROR:
  ------------------
  |  Branch (47:2): [True: 0, False: 349]
  ------------------
   48|       |	/* case Z_NEED_DICT: */
   49|      0|	default:
  ------------------
  |  Branch (49:2): [True: 0, False: 349]
  ------------------
   50|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   51|    349|	}
   52|    349|}
compression.c:detect_method:
   53|    470|static int detect_method(const u8* in, size_t inLen) {
   54|    470|	if (in != NULL && inLen > 1) {
  ------------------
  |  Branch (54:6): [True: 470, False: 0]
  |  Branch (54:20): [True: 450, False: 20]
  ------------------
   55|    450|		if (in[0] == 0x1f && in[1] == 0x8b)
  ------------------
  |  Branch (55:7): [True: 13, False: 437]
  |  Branch (55:24): [True: 2, False: 11]
  ------------------
   56|      2|			return COMPRESSION_GZIP;
  ------------------
  |  |   28|      2|#define COMPRESSION_GZIP	2
  ------------------
   57|       |		/*
   58|       |		 * A zlib stream has the following structure:
   59|       |		 *   0   1
   60|       |		 * +---+---+
   61|       |		 * |CMF|FLG|   (more-->)
   62|       |		 * +---+---+
   63|       |		 *
   64|       |		 * FLG (FLaGs)
   65|       |		 * 	This flag byte is divided as follows:
   66|       |		 *
   67|       |		 * 	bits 0 to 4  FCHECK  (check bits for CMF and FLG)
   68|       |		 * 	bit  5       FDICT   (preset dictionary)
   69|       |		 * 	bits 6 to 7  FLEVEL  (compression level)
   70|       |		 *
   71|       |		 * 	The FCHECK value must be such that CMF and FLG, when viewed as
   72|       |		 * 	a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG),
   73|       |		 * 	is a multiple of 31.
   74|       |		 */
   75|    448|		if ((((uint16_t) in[0])*256 + in[1]) % 31 == 0)
  ------------------
  |  Branch (75:7): [True: 346, False: 102]
  ------------------
   76|    346|			return COMPRESSION_ZLIB;
  ------------------
  |  |   27|    346|#define COMPRESSION_ZLIB	1
  ------------------
   77|    448|	}
   78|    122|	return COMPRESSION_UNKNOWN;
  ------------------
  |  |   29|    122|#define COMPRESSION_UNKNOWN (-1)
  ------------------
   79|    470|}
compression.c:sc_decompress_zlib_alloc:
  185|    349|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|    349|	z_stream gz;
  188|    349|	int err;
  189|    349|	int window_size = 15;
  190|    349|	const size_t startSize = inLen < 1024 ? 2048 : inLen * 2;
  ------------------
  |  Branch (190:27): [True: 209, False: 140]
  ------------------
  191|    349|	const size_t blockSize = inLen < 1024 ? 512 : inLen / 2;
  ------------------
  |  Branch (191:27): [True: 209, False: 140]
  ------------------
  192|    349|	size_t bufferSize = startSize;
  193|    349|	if (gzip)
  ------------------
  |  Branch (193:6): [True: 2, False: 347]
  ------------------
  194|      2|		window_size += 0x20;
  195|    349|	memset(&gz, 0, sizeof(gz));
  196|       |
  197|    349|	if (!out || !outLen)
  ------------------
  |  Branch (197:6): [True: 0, False: 349]
  |  Branch (197:14): [True: 0, False: 349]
  ------------------
  198|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  199|       |
  200|    349|	gz.next_in = (u8*)in;
  201|    349|	gz.avail_in = (unsigned)inLen;
  202|       |
  203|    349|	err = inflateInit2(&gz, window_size);
  204|    349|	if (err != Z_OK)
  ------------------
  |  Branch (204:6): [True: 0, False: 349]
  ------------------
  205|      0|		return zerr_to_opensc(err);
  206|       |
  207|    349|	*outLen = 0;
  208|       |
  209|    408|	while (1) {
  ------------------
  |  Branch (209:9): [True: 408, Folded]
  ------------------
  210|       |		/* Setup buffer... */
  211|    408|		size_t num;
  212|    408|		u8* buf = realloc(*out, bufferSize);
  213|    408|		if (!buf) {
  ------------------
  |  Branch (213:7): [True: 0, False: 408]
  ------------------
  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|    408|		*out = buf;
  220|    408|		gz.next_out = buf + *outLen;
  221|    408|		gz.avail_out = (unsigned)(bufferSize - *outLen);
  222|       |
  223|    408|		err = inflate(&gz, Z_FULL_FLUSH);
  224|    408|		if (err != Z_STREAM_END && err != Z_OK) {
  ------------------
  |  Branch (224:7): [True: 153, False: 255]
  |  Branch (224:30): [True: 94, False: 59]
  ------------------
  225|     94|			free(*out);
  226|     94|			*out = NULL;
  227|     94|			break;
  228|     94|		}
  229|    314|		num = *outLen + gz.avail_out;
  230|    314|		if (bufferSize > num) {
  ------------------
  |  Branch (230:7): [True: 313, False: 1]
  ------------------
  231|    313|			*outLen += bufferSize - num;
  232|    313|			bufferSize += bufferSize - num + blockSize;
  233|    313|		}
  234|    314|		if (err == Z_STREAM_END) {
  ------------------
  |  Branch (234:7): [True: 255, False: 59]
  ------------------
  235|    255|			if (*outLen > 0) {
  ------------------
  |  Branch (235:8): [True: 255, False: 0]
  ------------------
  236|       |				/* Shrink it down, if it fails, just use old data */
  237|    255|				buf = realloc(buf, *outLen);
  238|    255|				if (buf) {
  ------------------
  |  Branch (238:9): [True: 255, False: 0]
  ------------------
  239|    255|					*out = buf;
  240|    255|				}
  241|    255|			} else {
  242|      0|				free(*out);
  243|      0|				*out = NULL;
  244|      0|				err = Z_DATA_ERROR;
  245|      0|			}
  246|    255|			break;
  247|    255|		}
  248|    314|	}
  249|    349|	inflateEnd(&gz);
  250|    349|	return zerr_to_opensc(err);
  251|    349|}

_sc_delete_reader:
   86|  16.4k|{
   87|  16.4k|	if (reader == NULL) {
  ------------------
  |  Branch (87:6): [True: 0, False: 16.4k]
  ------------------
   88|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   89|      0|	}
   90|  16.4k|	if (reader->ops->release)
  ------------------
  |  Branch (90:6): [True: 16.4k, False: 0]
  ------------------
   91|  16.4k|			reader->ops->release(reader);
   92|  16.4k|	free(reader->name);
   93|  16.4k|	free(reader->vendor);
   94|  16.4k|	list_delete(&ctx->readers, reader);
   95|  16.4k|	free(reader);
   96|  16.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
   97|  16.4k|}
sc_ctx_detect_readers:
  781|  16.4k|{
  782|  16.4k|	int r = 0;
  783|  16.4k|	const struct sc_reader_driver *drv = ctx->reader_driver;
  784|       |
  785|  16.4k|	sc_mutex_lock(ctx, ctx->mutex);
  786|       |
  787|  16.4k|	if (drv->ops->detect_readers != NULL)
  ------------------
  |  Branch (787:6): [True: 0, False: 16.4k]
  ------------------
  788|      0|		r = drv->ops->detect_readers(ctx);
  789|       |
  790|  16.4k|	sc_mutex_unlock(ctx, ctx->mutex);
  791|       |
  792|  16.4k|	return r;
  793|  16.4k|}
sc_ctx_get_reader:
  796|  16.4k|{
  797|  16.4k|	return list_get_at(&ctx->readers, i);
  798|  16.4k|}
sc_establish_context:
  816|  16.4k|{
  817|  16.4k|	sc_context_param_t ctx_param;
  818|       |
  819|  16.4k|	memset(&ctx_param, 0, sizeof(sc_context_param_t));
  820|  16.4k|	ctx_param.ver      = 0;
  821|  16.4k|	ctx_param.app_name = app_name;
  822|  16.4k|	return sc_context_create(ctx_out, &ctx_param);
  823|  16.4k|}
sc_context_create:
  945|  16.4k|{
  946|  16.4k|	sc_context_t		*ctx;
  947|  16.4k|	struct _sc_ctx_options	opts;
  948|  16.4k|	int			r;
  949|  16.4k|	char			*driver;
  950|       |
  951|  16.4k|	if (ctx_out == NULL || parm == NULL)
  ------------------
  |  Branch (951:6): [True: 0, False: 16.4k]
  |  Branch (951:25): [True: 0, False: 16.4k]
  ------------------
  952|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  953|       |
  954|  16.4k|	ctx = calloc(1, sizeof(sc_context_t));
  955|  16.4k|	if (ctx == NULL)
  ------------------
  |  Branch (955:6): [True: 0, False: 16.4k]
  ------------------
  956|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  957|  16.4k|	memset(&opts, 0, sizeof(opts));
  958|       |
  959|       |	/* set the application name if set in the parameter options */
  960|  16.4k|	if (parm->app_name != NULL)
  ------------------
  |  Branch (960:6): [True: 16.4k, False: 0]
  ------------------
  961|  16.4k|		ctx->app_name = strdup(parm->app_name);
  962|      0|	else
  963|      0|		ctx->app_name = strdup("default");
  964|  16.4k|	if (ctx->app_name == NULL) {
  ------------------
  |  Branch (964:6): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	ctx->exe_path = get_exe_path();
  970|  16.4k|	if (ctx->exe_path == NULL) {
  ------------------
  |  Branch (970:6): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	ctx->flags = parm->flags;
  976|  16.4k|	set_defaults(ctx, &opts);
  977|       |
  978|  16.4k|	if (0 != list_init(&ctx->readers)) {
  ------------------
  |  Branch (978:6): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	list_attributes_seeker(&ctx->readers, reader_list_seeker);
  984|       |	/* set thread context and create mutex object (if specified) */
  985|  16.4k|	if (parm->thread_ctx != NULL)
  ------------------
  |  Branch (985:6): [True: 0, False: 16.4k]
  ------------------
  986|      0|		ctx->thread_ctx = parm->thread_ctx;
  987|  16.4k|	r = sc_mutex_create(ctx, &ctx->mutex);
  988|  16.4k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (988:6): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	process_config_file(ctx, &opts);
 1001|       |
 1002|       |	/* overwrite with caller's parameters if explicitly given */
 1003|  16.4k|	if (parm->debug) {
  ------------------
  |  Branch (1003:6): [True: 0, False: 16.4k]
  ------------------
 1004|      0|		ctx->debug = parm->debug;
 1005|      0|	}
 1006|  16.4k|	if (parm->debug_file) {
  ------------------
  |  Branch (1006:6): [True: 0, False: 16.4k]
  ------------------
 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|  16.4k|	sc_log(ctx, "==================================="); /* first thing in the log */
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
 1013|  16.4k|	sc_log(ctx, "OpenSC version: %s", sc_get_version());
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
 1014|  16.4k|	sc_log(ctx, "Configured for %s (%s)", ctx->app_name, ctx->exe_path);
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
 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|       |#else
 1034|       |	ctx->reader_driver = sc_get_empty_driver();
 1035|       |#endif
 1036|       |
 1037|  16.4k|	r = ctx->reader_driver->ops->init(ctx);
 1038|  16.4k|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1038:6): [True: 0, False: 16.4k]
  ------------------
 1039|      0|		del_drvs(&opts);
 1040|      0|		sc_release_context(ctx);
 1041|      0|		return r;
 1042|      0|	}
 1043|       |
 1044|  16.4k|	driver = getenv("OPENSC_DRIVER");
 1045|  16.4k|	if (driver) {
  ------------------
  |  Branch (1045:6): [True: 0, False: 16.4k]
  ------------------
 1046|      0|		scconf_list *list = NULL;
 1047|      0|		scconf_list_add(&list, driver);
 1048|      0|		set_drivers(&opts, list);
 1049|      0|		scconf_list_destroy(list);
 1050|      0|	}
 1051|       |
 1052|  16.4k|	load_card_drivers(ctx, &opts);
 1053|  16.4k|	load_card_atrs(ctx);
 1054|       |
 1055|  16.4k|	del_drvs(&opts);
 1056|  16.4k|	sc_ctx_detect_readers(ctx);
 1057|  16.4k|	*ctx_out = ctx;
 1058|       |
 1059|  16.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
 1060|  16.4k|}
sc_release_context:
 1093|  16.4k|{
 1094|  16.4k|	unsigned int i;
 1095|       |
 1096|  16.4k|	if (ctx == NULL) {
  ------------------
  |  Branch (1096:6): [True: 0, False: 16.4k]
  ------------------
 1097|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1098|      0|	}
 1099|  16.4k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  16.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  16.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  16.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 16.4k]
  |  |  ------------------
  ------------------
 1100|  32.9k|	while (list_size(&ctx->readers)) {
  ------------------
  |  Branch (1100:9): [True: 16.4k, False: 16.4k]
  ------------------
 1101|  16.4k|		sc_reader_t *rdr = (sc_reader_t *) list_get_at(&ctx->readers, 0);
 1102|  16.4k|		_sc_delete_reader(ctx, rdr);
 1103|  16.4k|	}
 1104|       |
 1105|  16.4k|	if (ctx->reader_driver != NULL && ctx->reader_driver->ops->finish != NULL)
  ------------------
  |  Branch (1105:6): [True: 16.4k, False: 0]
  |  Branch (1105:36): [True: 0, False: 16.4k]
  ------------------
 1106|      0|		ctx->reader_driver->ops->finish(ctx);
 1107|       |
 1108|   740k|	for (i = 0; ctx->card_drivers[i]; i++) {
  ------------------
  |  Branch (1108:14): [True: 724k, False: 16.4k]
  ------------------
 1109|   724k|		struct sc_card_driver *drv = ctx->card_drivers[i];
 1110|       |
 1111|   724k|		if (drv->atr_map)
  ------------------
  |  Branch (1111:7): [True: 0, False: 724k]
  ------------------
 1112|      0|			_sc_free_atr(ctx, drv);
 1113|   724k|		if (drv->dll)
  ------------------
  |  Branch (1113:7): [True: 0, False: 724k]
  ------------------
 1114|      0|			sc_dlclose(drv->dll);
 1115|   724k|	}
 1116|       |#ifdef USE_OPENSSL3_LIBCTX
 1117|       |	sc_openssl3_deinit(ctx);
 1118|       |#endif
 1119|  16.4k|	if (ctx->preferred_language != NULL)
  ------------------
  |  Branch (1119:6): [True: 0, False: 16.4k]
  ------------------
 1120|      0|		free(ctx->preferred_language);
 1121|  16.4k|	if (ctx->mutex != NULL) {
  ------------------
  |  Branch (1121:6): [True: 0, False: 16.4k]
  ------------------
 1122|      0|		int r = sc_mutex_destroy(ctx, ctx->mutex);
 1123|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1123:7): [True: 0, False: 0]
  ------------------
 1124|      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__
  |  |  ------------------
  ------------------
 1125|      0|			return r;
 1126|      0|		}
 1127|      0|	}
 1128|  16.4k|	if (ctx->conf != NULL)
  ------------------
  |  Branch (1128:6): [True: 16.4k, False: 0]
  ------------------
 1129|  16.4k|		scconf_free(ctx->conf);
 1130|  16.4k|	if (ctx->debug_file && (ctx->debug_file != stdout && ctx->debug_file != stderr))
  ------------------
  |  Branch (1130:6): [True: 16.4k, False: 0]
  |  Branch (1130:26): [True: 16.4k, False: 0]
  |  Branch (1130:55): [True: 0, False: 16.4k]
  ------------------
 1131|      0|		fclose(ctx->debug_file);
 1132|  16.4k|	free(ctx->debug_filename);
 1133|  16.4k|	free(ctx->app_name);
 1134|  16.4k|	free(ctx->exe_path);
 1135|  16.4k|	list_destroy(&ctx->readers);
 1136|  16.4k|	sc_mem_clear(ctx, sizeof(*ctx));
 1137|  16.4k|	free(ctx);
 1138|  16.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
 1139|  16.4k|}
sc_get_cache_dir:
 1166|  3.58k|{
 1167|  3.58k|	char *homedir;
 1168|  3.58k|	const char *cache_dir;
 1169|  3.58k|        scconf_block *conf_block = NULL;
 1170|       |#ifdef _WIN32
 1171|       |	char temp_path[PATH_MAX];
 1172|       |#endif
 1173|  3.58k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1174|  3.58k|	cache_dir = scconf_get_str(conf_block, "file_cache_dir", NULL);
 1175|  3.58k|	if (cache_dir != NULL) {
  ------------------
  |  Branch (1175:6): [True: 0, False: 3.58k]
  ------------------
 1176|      0|		strlcpy(buf, cache_dir, bufsize);
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1177|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1178|      0|	}
 1179|       |
 1180|  3.58k|#ifndef _WIN32
 1181|       |#ifdef __APPLE__
 1182|       |	cache_dir = getenv("Caches");
 1183|       |#else
 1184|  3.58k|	cache_dir = getenv("XDG_CACHE_HOME");
 1185|  3.58k|#endif
 1186|  3.58k|	if (cache_dir != NULL && cache_dir[0] != '\0') {
  ------------------
  |  Branch (1186:6): [True: 0, False: 3.58k]
  |  Branch (1186:27): [True: 0, False: 0]
  ------------------
 1187|      0|		snprintf(buf, bufsize, "%s/%s", cache_dir, "opensc");
 1188|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1189|      0|	}
 1190|  3.58k|	cache_dir = ".cache/opensc";
 1191|  3.58k|	homedir = getenv("HOME");
 1192|       |#else
 1193|       |	cache_dir = "eid-cache";
 1194|       |	homedir = getenv("USERPROFILE");
 1195|       |	/* If USERPROFILE isn't defined, assume it's a single-user OS
 1196|       |	 * and put the cache dir in the Windows dir (usually C:\\WINDOWS) */
 1197|       |	if (homedir == NULL || homedir[0] == '\0') {
 1198|       |		GetWindowsDirectoryA(temp_path, sizeof(temp_path));
 1199|       |		homedir = temp_path;
 1200|       |	}
 1201|       |#endif
 1202|  3.58k|	if (homedir == NULL || homedir[0] == '\0')
  ------------------
  |  Branch (1202:6): [True: 0, False: 3.58k]
  |  Branch (1202:25): [True: 0, False: 3.58k]
  ------------------
 1203|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1204|  3.58k|	if (snprintf(buf, bufsize, "%s/%s", homedir, cache_dir) < 0)
  ------------------
  |  Branch (1204:6): [True: 0, False: 3.58k]
  ------------------
 1205|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1206|  3.58k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.58k|#define SC_SUCCESS				0
  ------------------
 1207|  3.58k|}
sc_make_cache_dir:
 1210|     49|{
 1211|     49|	char dirname[PATH_MAX], *sp;
 1212|     49|	int    r, mkdir_checker;
 1213|     49|	size_t j, namelen;
 1214|       |
 1215|     49|	if ((r = sc_get_cache_dir(ctx, dirname, sizeof(dirname))) < 0)
  ------------------
  |  Branch (1215:6): [True: 0, False: 49]
  ------------------
 1216|      0|		return r;
 1217|     49|	namelen = strlen(dirname);
 1218|       |
 1219|     49|	while (1) {
  ------------------
  |  Branch (1219:9): [True: 49, Folded]
  ------------------
 1220|       |#ifdef _WIN32
 1221|       |		mkdir_checker = mkdir(dirname) >= 0;
 1222|       |#else
 1223|     49|		mkdir_checker = mkdir(dirname, 0700) >= 0;
 1224|     49|#endif
 1225|     49|		if (mkdir_checker)
  ------------------
  |  Branch (1225:7): [True: 0, False: 49]
  ------------------
 1226|      0|			break;
 1227|       |
 1228|     49|		if (errno != ENOENT || (sp = strrchr(dirname, '/')) == NULL
  ------------------
  |  Branch (1228:7): [True: 49, False: 0]
  |  Branch (1228:26): [True: 0, False: 0]
  ------------------
 1229|      0|				|| sp == dirname)
  ------------------
  |  Branch (1229:8): [True: 0, False: 0]
  ------------------
 1230|     49|			goto failed;
 1231|      0|		*sp = '\0';
 1232|      0|	}
 1233|       |
 1234|       |	/* We may have stripped one or more path components from
 1235|       |	 * the directory name. Restore them */
 1236|      0|	while (1) {
  ------------------
  |  Branch (1236:9): [True: 0, Folded]
  ------------------
 1237|      0|		j = strlen(dirname);
 1238|      0|		if (j >= namelen)
  ------------------
  |  Branch (1238:7): [True: 0, False: 0]
  ------------------
 1239|      0|			break;
 1240|      0|		dirname[j] = '/';
 1241|       |#ifdef _WIN32
 1242|       |		mkdir_checker = mkdir(dirname) < 0;
 1243|       |#else
 1244|      0|		mkdir_checker = mkdir(dirname, 0700) < 0;
 1245|      0|#endif
 1246|      0|		if (mkdir_checker)
  ------------------
  |  Branch (1246:7): [True: 0, False: 0]
  ------------------
 1247|      0|			goto failed;
 1248|      0|	}
 1249|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1250|       |
 1251|       |	/* for lack of a better return code */
 1252|     49|failed:
 1253|     49|	sc_log(ctx, "failed to create cache directory");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1254|     49|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     49|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1255|      0|}
ctx.c:load_card_atrs:
  629|  16.4k|{
  630|  16.4k|	struct sc_card_driver *driver;
  631|  16.4k|	scconf_block **blocks;
  632|  16.4k|	int i, j, k;
  633|       |
  634|  32.9k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (634:14): [True: 16.4k, False: 16.4k]
  ------------------
  635|  16.4k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], "card_atr", NULL);
  636|  16.4k|		if (!blocks)
  ------------------
  |  Branch (636:7): [True: 0, False: 16.4k]
  ------------------
  637|      0|			continue;
  638|  16.4k|		for (j = 0; blocks[j] != NULL; j++) {
  ------------------
  |  Branch (638:15): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|		free(blocks);
  700|  16.4k|	}
  701|  16.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
  702|  16.4k|}
ctx.c:get_exe_path:
  910|  16.4k|{
  911|       |	/* Find the executable's path which runs this code.
  912|       |	 * See https://github.com/gpakosz/whereami/ for
  913|       |	 * potentially more platforms */
  914|  16.4k|	char exe_path[PATH_MAX] = "unknown executable path";
  915|  16.4k|	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|  16.4k|	if (NULL != realpath("/proc/self/exe", exe_path))
  ------------------
  |  Branch (924:6): [True: 16.4k, False: 0]
  ------------------
  925|  16.4k|		path_found = 1;
  926|  16.4k|#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|  16.4k|	(void) path_found;
  939|  16.4k|#endif
  940|       |
  941|  16.4k|	return strdup(exe_path);
  942|  16.4k|}
ctx.c:set_defaults:
  321|  16.4k|{
  322|  16.4k|	ctx->debug = 0;
  323|  16.4k|	if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  ------------------
  |  Branch (323:6): [True: 0, False: 16.4k]
  |  Branch (323:26): [True: 0, False: 0]
  |  Branch (323:55): [True: 0, False: 0]
  ------------------
  324|      0|		fclose(ctx->debug_file);
  325|  16.4k|	ctx->debug_file = stderr;
  326|  16.4k|	ctx->flags = 0;
  327|       |	ctx->forced_driver = NULL;
  328|  16.4k|	add_internal_drvs(opts);
  329|  16.4k|}
ctx.c:add_internal_drvs:
  295|  32.9k|{
  296|  32.9k|	const struct _sc_driver_entry *lst;
  297|  32.9k|	int i;
  298|       |
  299|  32.9k|	lst = internal_card_drivers;
  300|  32.9k|	i = 0;
  301|  1.31M|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (301:9): [True: 1.28M, False: 32.9k]
  ------------------
  302|  1.28M|		add_drv(opts, lst[i].name);
  303|  1.28M|		i++;
  304|  1.28M|	}
  305|  32.9k|}
ctx.c:add_drv:
  277|  1.36M|{
  278|  1.36M|	struct _sc_driver_entry *lst;
  279|  1.36M|	int *cp, max, i;
  280|       |
  281|  1.36M|	lst = opts->cdrv;
  282|  1.36M|	cp = &opts->ccount;
  283|  1.36M|	max = SC_MAX_CARD_DRIVERS;
  ------------------
  |  |   31|  1.36M|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  284|  1.36M|	if (*cp == max) /* No space for more drivers... */
  ------------------
  |  Branch (284:6): [True: 0, False: 1.36M]
  ------------------
  285|      0|		return;
  286|  29.1M|	for (i = 0; i < *cp; i++)
  ------------------
  |  Branch (286:14): [True: 27.7M, False: 1.36M]
  ------------------
  287|  27.7M|		if (strcmp(name, lst[i].name) == 0)
  ------------------
  |  Branch (287:7): [True: 0, False: 27.7M]
  ------------------
  288|      0|			return;
  289|  1.36M|	lst[*cp].name = strdup(name);
  290|       |
  291|  1.36M|	*cp = *cp + 1;
  292|  1.36M|}
ctx.c:del_drvs:
  263|  32.9k|{
  264|  32.9k|	struct _sc_driver_entry *lst;
  265|  32.9k|	int *cp, i;
  266|       |
  267|  32.9k|	lst = opts->cdrv;
  268|  32.9k|	cp = &opts->ccount;
  269|       |
  270|  1.39M|	for (i = 0; i < *cp; i++) {
  ------------------
  |  Branch (270:14): [True: 1.36M, False: 32.9k]
  ------------------
  271|  1.36M|		free((void *)lst[i].name);
  272|  1.36M|	}
  273|  32.9k|	*cp = 0;
  274|  32.9k|}
ctx.c:process_config_file:
  705|  16.4k|{
  706|  16.4k|	int i, r, count = 0;
  707|  16.4k|	scconf_block **blocks;
  708|  16.4k|	const char *conf_path = NULL;
  709|  16.4k|	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|  16.4k|	debug = getenv("OPENSC_DEBUG");
  717|  16.4k|	if (debug)
  ------------------
  |  Branch (717:6): [True: 0, False: 16.4k]
  ------------------
  718|      0|		ctx->debug = atoi(debug);
  719|       |
  720|  16.4k|	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|  16.4k|	conf_path = getenv("OPENSC_CONF");
  733|  16.4k|	if (!conf_path)
  ------------------
  |  Branch (733:6): [True: 16.4k, False: 0]
  ------------------
  734|  16.4k|		conf_path = OPENSC_CONF_PATH;
  735|  16.4k|#endif
  736|  16.4k|	ctx->conf = scconf_new(conf_path);
  737|  16.4k|	if (ctx->conf == NULL)
  ------------------
  |  Branch (737:6): [True: 0, False: 16.4k]
  ------------------
  738|      0|		return;
  739|  16.4k|	r = scconf_parse(ctx->conf);
  740|  16.4k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  741|  16.4k|#ifdef OPENSC_CONFIG_STRING
  742|       |	/* Parse the string if config file didn't exist */
  743|  16.4k|	if (r < 0)
  ------------------
  |  Branch (743:6): [True: 16.4k, False: 0]
  ------------------
  744|  16.4k|		r = scconf_parse_string(ctx->conf, OPENSC_CONFIG_STRING);
  ------------------
  |  |  740|  16.4k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  ------------------
  745|  16.4k|#endif
  746|  16.4k|	if (r < 1) {
  ------------------
  |  Branch (746:6): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	sc_log(ctx, "Used configuration file '%s'", conf_path);
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
  760|  16.4k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->exe_path);
  761|  16.4k|	if (blocks && blocks[0])
  ------------------
  |  Branch (761:6): [True: 16.4k, False: 0]
  |  Branch (761:16): [True: 0, False: 16.4k]
  ------------------
  762|      0|		ctx->conf_blocks[count++] = blocks[0];
  763|  16.4k|	free(blocks);
  764|  16.4k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->app_name);
  765|  16.4k|	if (blocks && blocks[0])
  ------------------
  |  Branch (765:6): [True: 16.4k, False: 0]
  |  Branch (765:16): [True: 0, False: 16.4k]
  ------------------
  766|      0|		ctx->conf_blocks[count++] = blocks[0];
  767|  16.4k|	free(blocks);
  768|  16.4k|	if (strcmp(ctx->app_name, "default") != 0) {
  ------------------
  |  Branch (768:6): [True: 16.4k, False: 0]
  ------------------
  769|  16.4k|		blocks = scconf_find_blocks(ctx->conf, NULL, "app", "default");
  770|  16.4k|		if (blocks && blocks[0])
  ------------------
  |  Branch (770:7): [True: 16.4k, False: 0]
  |  Branch (770:17): [True: 16.4k, False: 0]
  ------------------
  771|  16.4k|			ctx->conf_blocks[count] = blocks[0];
  772|  16.4k|		free(blocks);
  773|  16.4k|	}
  774|       |	/* Above we add 3 blocks at most, but conf_blocks has 4 elements,
  775|       |	 * so at least one is NULL */
  776|  32.9k|	for (i = 0; ctx->conf_blocks[i]; i++)
  ------------------
  |  Branch (776:14): [True: 16.4k, False: 16.4k]
  ------------------
  777|  16.4k|		load_parameters(ctx, ctx->conf_blocks[i], opts);
  778|  16.4k|}
ctx.c:load_parameters:
  384|  16.4k|{
  385|  16.4k|	int err = 0;
  386|  16.4k|	const scconf_list *list;
  387|  16.4k|	const char *val;
  388|  16.4k|	int debug;
  389|  16.4k|	const char *disable_hw_pkcs1_padding;
  390|       |#ifdef _WIN32
  391|       |	char expanded_val[PATH_MAX];
  392|       |	DWORD expanded_len;
  393|       |#endif
  394|       |
  395|  16.4k|	debug = scconf_get_int(block, "debug", ctx->debug);
  396|  16.4k|	if (debug > ctx->debug)
  ------------------
  |  Branch (396:6): [True: 0, False: 16.4k]
  ------------------
  397|      0|		ctx->debug = debug;
  398|       |
  399|  16.4k|	val = scconf_get_str(block, "debug_file", NULL);
  400|  16.4k|	if (val)   {
  ------------------
  |  Branch (400:6): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	else if (ctx->debug)   {
  ------------------
  |  Branch (409:11): [True: 0, False: 16.4k]
  ------------------
  410|      0|		sc_ctx_log_to_file(ctx, NULL);
  411|      0|	}
  412|       |
  413|  16.4k|	if (scconf_get_bool (block, "disable_popups",
  ------------------
  |  Branch (413:6): [True: 0, False: 16.4k]
  ------------------
  414|  16.4k|				ctx->flags & SC_CTX_FLAG_DISABLE_POPUPS))
  ------------------
  |  |  868|  16.4k|#define SC_CTX_FLAG_DISABLE_POPUPS			0x00000010
  ------------------
  415|      0|		ctx->flags |= SC_CTX_FLAG_DISABLE_POPUPS;
  ------------------
  |  |  868|      0|#define SC_CTX_FLAG_DISABLE_POPUPS			0x00000010
  ------------------
  416|       |
  417|  16.4k|	if (scconf_get_bool (block, "disable_colors",
  ------------------
  |  Branch (417:6): [True: 0, False: 16.4k]
  ------------------
  418|  16.4k|				ctx->flags & SC_CTX_FLAG_DISABLE_COLORS))
  ------------------
  |  |  869|  16.4k|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  419|      0|		ctx->flags |= SC_CTX_FLAG_DISABLE_COLORS;
  ------------------
  |  |  869|      0|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  420|       |
  421|  16.4k|	if (scconf_get_bool (block, "enable_default_driver",
  ------------------
  |  Branch (421:6): [True: 0, False: 16.4k]
  ------------------
  422|  16.4k|				ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER))
  ------------------
  |  |  867|  16.4k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  423|      0|		ctx->flags |= SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER;
  ------------------
  |  |  867|      0|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  424|       |
  425|  16.4k|	list = scconf_find_list(block, "card_drivers");
  426|  16.4k|	set_drivers(opts, list);
  427|       |
  428|       |	/* Disable PKCS#1 v1.5 type 2 (for decryption) depadding on card by default */
  429|  16.4k|	disable_hw_pkcs1_padding = "decipher";
  430|  16.4k|	ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  119|  16.4k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  431|  16.4k|	disable_hw_pkcs1_padding = scconf_get_str(block, "disable_hw_pkcs1_padding", disable_hw_pkcs1_padding);
  432|  16.4k|	if (0 == strcmp(disable_hw_pkcs1_padding, "no")) {
  ------------------
  |  Branch (432:6): [True: 0, False: 16.4k]
  ------------------
  433|      0|		ctx->disable_hw_pkcs1_padding = 0;
  434|  16.4k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "sign")) {
  ------------------
  |  Branch (434:13): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "decipher")) {
  ------------------
  |  Branch (436:13): [True: 16.4k, False: 0]
  ------------------
  437|  16.4k|		ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  119|  16.4k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  438|  16.4k|	} 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|  16.4k|	return err;
  450|  16.4k|}
ctx.c:set_drivers:
  367|  16.4k|{
  368|  16.4k|	const char *s_internal = "internal", *s_old = "old";
  369|  16.4k|	if (list != NULL)
  ------------------
  |  Branch (369:6): [True: 16.4k, False: 0]
  ------------------
  370|  16.4k|		del_drvs(opts);
  371|  49.3k|	while (list != NULL) {
  ------------------
  |  Branch (371:9): [True: 32.9k, False: 16.4k]
  ------------------
  372|  32.9k|		if (strcmp(list->data, s_internal) == 0)
  ------------------
  |  Branch (372:7): [True: 16.4k, False: 16.4k]
  ------------------
  373|  16.4k|			add_internal_drvs(opts);
  374|  16.4k|		else if (strcmp(list->data, s_old) == 0)
  ------------------
  |  Branch (374:12): [True: 16.4k, False: 0]
  ------------------
  375|  16.4k|			add_old_drvs(opts);
  376|      0|		else
  377|      0|			add_drv(opts, list->data);
  378|  32.9k|		list = list->next;
  379|  32.9k|	}
  380|  16.4k|}
ctx.c:add_old_drvs:
  308|  16.4k|{
  309|  16.4k|	const struct _sc_driver_entry *lst;
  310|  16.4k|	int i;
  311|       |
  312|  16.4k|	lst = old_card_drivers;
  313|  16.4k|	i = 0;
  314|  98.7k|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (314:9): [True: 82.3k, False: 16.4k]
  ------------------
  315|  82.3k|		add_drv(opts, lst[i].name);
  316|  82.3k|		i++;
  317|  82.3k|	}
  318|  16.4k|}
ctx.c:load_card_drivers:
  563|  16.4k|{
  564|  16.4k|	const struct _sc_driver_entry *ent;
  565|  16.4k|	int drv_count;
  566|  16.4k|	int i;
  567|       |
  568|  16.4k|	for (drv_count = 0; ctx->card_drivers[drv_count] != NULL; drv_count++)
  ------------------
  |  Branch (568:22): [True: 0, False: 16.4k]
  ------------------
  569|      0|		;
  570|       |
  571|   740k|	for (i = 0; i < opts->ccount; i++) {
  ------------------
  |  Branch (571:14): [True: 724k, False: 16.4k]
  ------------------
  572|   724k|		struct sc_card_driver *(*func)(void) = NULL;
  573|   724k|		struct sc_card_driver *(**tfunc)(void) = &func;
  574|   724k|		void *dll = NULL;
  575|   724k|		int  j;
  576|       |
  577|   724k|		if (drv_count >= SC_MAX_CARD_DRIVERS - 1)   {
  ------------------
  |  |   31|   724k|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  |  Branch (577:7): [True: 0, False: 724k]
  ------------------
  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|   724k|		ent = &opts->cdrv[i];
  583|  16.1M|		for (j = 0; internal_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (583:15): [True: 16.0M, False: 82.3k]
  ------------------
  584|  16.0M|			if (strcmp(ent->name, internal_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (584:8): [True: 641k, False: 15.4M]
  ------------------
  585|   641k|				func = (struct sc_card_driver *(*)(void)) internal_card_drivers[j].func;
  586|   641k|				break;
  587|   641k|			}
  588|  16.0M|		}
  589|   724k|		if (func == NULL) {
  ------------------
  |  Branch (589:7): [True: 82.3k, False: 641k]
  ------------------
  590|   246k|			for (j = 0; old_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (590:16): [True: 246k, False: 0]
  ------------------
  591|   246k|				if (strcmp(ent->name, old_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (591:9): [True: 82.3k, False: 164k]
  ------------------
  592|  82.3k|					func = (struct sc_card_driver *(*)(void)) old_card_drivers[j].func;
  593|  82.3k|					break;
  594|  82.3k|				}
  595|   246k|			}
  596|  82.3k|		}
  597|       |		/* if not initialized assume external module */
  598|   724k|		if (func == NULL)
  ------------------
  |  Branch (598:7): [True: 0, False: 724k]
  ------------------
  599|      0|			*(void **)(tfunc) = load_dynamic_driver(ctx, &dll, ent->name);
  600|       |		/* if still null, assume driver not found */
  601|   724k|		if (func == NULL) {
  ------------------
  |  Branch (601:7): [True: 0, False: 724k]
  ------------------
  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|   724k|		ctx->card_drivers[drv_count] = func();
  609|   724k|		if (ctx->card_drivers[drv_count] == NULL) {
  ------------------
  |  Branch (609:7): [True: 0, False: 724k]
  ------------------
  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|   724k|		ctx->card_drivers[drv_count]->dll = dll;
  615|   724k|		ctx->card_drivers[drv_count]->atr_map = NULL;
  616|   724k|		ctx->card_drivers[drv_count]->natrs = 0;
  617|       |
  618|   724k|		load_card_driver_options(ctx, ctx->card_drivers[drv_count]);
  619|       |
  620|       |		/* Ensure that the list is always terminated by NULL */
  621|   724k|		ctx->card_drivers[drv_count + 1] = NULL;
  622|       |
  623|   724k|		drv_count++;
  624|   724k|	}
  625|  16.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
  626|  16.4k|}
ctx.c:load_card_driver_options:
  542|   724k|{
  543|   724k|	scconf_block **blocks, *blk;
  544|   724k|	int i;
  545|       |
  546|  1.44M|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (546:14): [True: 724k, False: 724k]
  ------------------
  547|   724k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  548|   724k|				"card_driver", driver->short_name);
  549|   724k|		if (!blocks)
  ------------------
  |  Branch (549:7): [True: 0, False: 724k]
  ------------------
  550|      0|			continue;
  551|   724k|		blk = blocks[0];
  552|   724k|		free(blocks);
  553|       |
  554|   724k|		if (blk == NULL)
  ------------------
  |  Branch (554:7): [True: 724k, False: 0]
  ------------------
  555|   724k|			continue;
  556|       |
  557|       |		/* no options at the moment */
  558|   724k|	}
  559|   724k|	return SC_SUCCESS;
  ------------------
  |  |   28|   724k|#define SC_SUCCESS				0
  ------------------
  560|   724k|}

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

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

sc_enum_apps:
  163|  11.9k|{
  164|  11.9k|	struct sc_context *ctx = card->ctx;
  165|  11.9k|	sc_path_t path;
  166|  11.9k|	int ef_structure;
  167|  11.9k|	size_t file_size, jj;
  168|  11.9k|	int r, ii, idx;
  169|  11.9k|	struct sc_file *ef_dir = NULL;
  170|       |
  171|  11.9k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  11.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  172|       |
  173|  11.9k|	sc_free_apps(card);
  174|  11.9k|	card->app_count = 0;
  175|       |
  176|  11.9k|	sc_format_path("3F002F00", &path);
  177|  11.9k|	r = sc_select_file(card, &path, &ef_dir);
  178|  11.9k|	if (r < 0)
  ------------------
  |  Branch (178:6): [True: 9.60k, False: 2.35k]
  ------------------
  179|  9.60k|		sc_file_free(ef_dir);
  180|  11.9k|	LOG_TEST_RET(ctx, r, "Cannot select EF.DIR file");
  ------------------
  |  |  174|  11.9k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  11.9k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  11.9k|	int _ret = (r); \
  |  |  |  |  168|  11.9k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9.60k, False: 2.35k]
  |  |  |  |  ------------------
  |  |  |  |  169|  9.60k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.60k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  9.60k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  9.60k|		return _ret; \
  |  |  |  |  172|  9.60k|	} \
  |  |  |  |  173|  11.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.35k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  181|       |
  182|  2.35k|	if (ef_dir->type != SC_FILE_TYPE_WORKING_EF) {
  ------------------
  |  |  216|  2.35k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (182:6): [True: 1.30k, False: 1.05k]
  ------------------
  183|  1.30k|		sc_file_free(ef_dir);
  184|  1.30k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_CARD, "EF(DIR) is not a working EF.");
  ------------------
  |  |  174|  1.30k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.30k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.30k|	int _ret = (r); \
  |  |  |  |  168|  1.30k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.30k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.30k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.30k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.30k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.30k|		return _ret; \
  |  |  |  |  172|  1.30k|	} \
  |  |  |  |  173|  1.30k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  185|  1.30k|	}
  186|       |
  187|  1.05k|	ef_structure = ef_dir->ef_structure;
  188|  1.05k|	file_size = ef_dir->size;
  189|  1.05k|	sc_file_free(ef_dir);
  190|  1.05k|	if (ef_structure == SC_FILE_EF_TRANSPARENT) {
  ------------------
  |  |  221|  1.05k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (190:6): [True: 565, False: 486]
  ------------------
  191|    565|		u8 *buf = NULL, *p;
  192|    565|		size_t bufsize;
  193|       |
  194|    565|		if (file_size == 0)
  ------------------
  |  Branch (194:7): [True: 33, False: 532]
  ------------------
  195|    565|			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|    532|		if (file_size > MAX_FILE_SIZE)
  ------------------
  |  |  229|    532|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (196:7): [True: 22, False: 510]
  ------------------
  197|    532|			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|    510|		buf = malloc(file_size);
  200|    510|		if (buf == NULL)
  ------------------
  |  Branch (200:7): [True: 0, False: 510]
  ------------------
  201|    510|			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|    510|		p = buf;
  203|    510|		r = sc_read_binary(card, 0, buf, file_size, 0);
  204|    510|		if (r < 0) {
  ------------------
  |  Branch (204:7): [True: 201, False: 309]
  ------------------
  205|    201|			free(buf);
  206|    201|			LOG_TEST_RET(ctx, r, "sc_read_binary() 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|    201|		}
  208|    309|		bufsize = r;
  209|    603|		while (bufsize > 0) {
  ------------------
  |  Branch (209:10): [True: 445, False: 158]
  ------------------
  210|    445|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|    445|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (210:8): [True: 1, False: 444]
  ------------------
  211|      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__
  |  |  ------------------
  ------------------
  212|      1|				break;
  213|      1|			}
  214|    444|			r = parse_dir_record(card, &p, &bufsize, -1);
  215|    444|			if (r)
  ------------------
  |  Branch (215:8): [True: 150, False: 294]
  ------------------
  216|    150|				break;
  217|    444|		}
  218|    309|		if (buf)
  ------------------
  |  Branch (218:7): [True: 309, False: 0]
  ------------------
  219|    309|			free(buf);
  220|       |
  221|    309|	}
  222|    486|	else {	/* record structure */
  223|    486|		unsigned char buf[256], *p;
  224|    486|		unsigned int rec_nr;
  225|    486|		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.29k|		for (rec_nr = 1; rec_nr < 16; rec_nr++) {
  ------------------
  |  Branch (229:20): [True: 1.28k, False: 6]
  ------------------
  230|  1.28k|			r = sc_read_record(card, rec_nr, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1305|  1.28k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  231|  1.28k|			if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|  1.28k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (231:8): [True: 1, False: 1.28k]
  ------------------
  232|      1|				break;
  233|  1.28k|			LOG_TEST_RET(ctx, r, "read_record() failed");
  ------------------
  |  |  174|  1.28k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.28k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.28k|	int _ret = (r); \
  |  |  |  |  168|  1.28k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 478, False: 808]
  |  |  |  |  ------------------
  |  |  |  |  169|    478|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    478|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    478|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    478|		return _ret; \
  |  |  |  |  172|    478|	} \
  |  |  |  |  173|  1.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 808]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|       |
  235|    808|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|    808|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (235:8): [True: 1, False: 807]
  ------------------
  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|    807|			rec_size = r;
  241|    807|			p = buf;
  242|    807|			parse_dir_record(card, &p, &rec_size, (int)rec_nr);
  243|    807|		}
  244|    486|	}
  245|       |
  246|       |	/* Move known PKCS#15 applications to the head of the list */
  247|    626|	for (ii=0, idx=0; ii<card->app_count; ii++)   {
  ------------------
  |  Branch (247:20): [True: 309, False: 317]
  ------------------
  248|  2.59k|		for (jj=0; jj < sizeof(apps)/sizeof(apps[0]); jj++) {
  ------------------
  |  Branch (248:14): [True: 2.32k, False: 278]
  ------------------
  249|  2.32k|			if (apps[jj].aid_len != card->app[ii]->aid.len)
  ------------------
  |  Branch (249:8): [True: 2.19k, False: 126]
  ------------------
  250|  2.19k|				continue;
  251|    126|			if (memcmp(apps[jj].aid, card->app[ii]->aid.value, apps[jj].aid_len))
  ------------------
  |  Branch (251:8): [True: 95, False: 31]
  ------------------
  252|     95|				continue;
  253|     31|			break;
  254|    126|		}
  255|       |
  256|    309|		if (ii != idx && jj < sizeof(apps)/sizeof(apps[0]))   {
  ------------------
  |  Branch (256:7): [True: 98, False: 211]
  |  Branch (256:20): [True: 21, False: 77]
  ------------------
  257|     21|			struct sc_app_info *tmp = card->app[idx];
  258|       |
  259|     21|			card->app[idx] = card->app[ii];
  260|     21|			card->app[ii] = tmp;
  261|     21|			idx++;
  262|     21|		}
  263|    309|	}
  264|       |
  265|    317|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    317|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    317|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    317|	int _ret = r; \
  |  |  |  |  155|    317|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 317, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    317|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 317]
  |  |  |  |  ------------------
  |  |  |  |  157|    317|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    317|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    317|	return _ret; \
  |  |  |  |  163|    317|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|    317|}
sc_free_apps:
  269|  28.4k|{
  270|  28.4k|	int	i;
  271|       |
  272|  28.9k|	for (i = 0; i < card->app_count; i++) {
  ------------------
  |  Branch (272:14): [True: 540, False: 28.4k]
  ------------------
  273|    540|		free(card->app[i]->label);
  274|    540|		free(card->app[i]->ddo.value);
  275|    540|		free(card->app[i]);
  276|    540|	}
  277|  28.4k|	card->app_count = -1;
  278|  28.4k|}
dir.c:parse_dir_record:
   65|  1.25k|{
   66|  1.25k|	struct sc_context *ctx = card->ctx;
   67|  1.25k|	struct sc_asn1_entry asn1_dirrecord[5], asn1_dir[2];
   68|  1.25k|	scconf_block *conf_block = NULL;
   69|  1.25k|	sc_app_info_t *app = NULL;
   70|  1.25k|	struct sc_aid aid;
   71|  1.25k|	u8 label[128], path[128], ddo[128];
   72|  1.25k|	size_t label_len = sizeof(label) - 1, path_len = sizeof(path), ddo_len = sizeof(ddo);
   73|  1.25k|	int r;
   74|       |
   75|  1.25k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.25k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.25k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.25k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.25k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.25k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   76|  1.25k|	aid.len = sizeof(aid.value);
   77|       |
   78|  1.25k|	memset(label, 0, sizeof(label));
   79|  1.25k|	sc_copy_asn1_entry(c_asn1_dirrecord, asn1_dirrecord);
   80|  1.25k|	sc_copy_asn1_entry(c_asn1_dir, asn1_dir);
   81|  1.25k|	sc_format_asn1_entry(asn1_dir + 0, asn1_dirrecord, NULL, 0);
   82|  1.25k|	sc_format_asn1_entry(asn1_dirrecord + 0, aid.value, &aid.len, 0);
   83|  1.25k|	sc_format_asn1_entry(asn1_dirrecord + 1, label, &label_len, 0);
   84|  1.25k|	sc_format_asn1_entry(asn1_dirrecord + 2, path, &path_len, 0);
   85|  1.25k|	sc_format_asn1_entry(asn1_dirrecord + 3, ddo, &ddo_len, 0);
   86|       |
   87|  1.25k|	r = sc_asn1_decode(ctx, asn1_dir, *buf, *buflen, (const u8 **) buf, buflen);
   88|  1.25k|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|  1.25k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (88:6): [True: 58, False: 1.19k]
  ------------------
   89|  1.25k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     58|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     58|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     58|	int _ret = r; \
  |  |  |  |  155|     58|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     58|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     58|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     58|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     58|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     58|	return _ret; \
  |  |  |  |  163|     58|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|  1.19k|	LOG_TEST_RET(ctx, r, "EF(DIR) parsing failed");
  ------------------
  |  |  174|  1.19k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.19k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.19k|	int _ret = (r); \
  |  |  |  |  168|  1.19k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 643, False: 550]
  |  |  |  |  ------------------
  |  |  |  |  169|    643|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    643|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    643|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    643|		return _ret; \
  |  |  |  |  172|    643|	} \
  |  |  |  |  173|  1.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 550]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|       |
   92|    550|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
   93|    550|	if (conf_block)   {
  ------------------
  |  Branch (93:6): [True: 0, False: 550]
  ------------------
   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|    550|	app = calloc(1, sizeof(struct sc_app_info));
  112|    550|	if (app == NULL)
  ------------------
  |  Branch (112:6): [True: 0, False: 550]
  ------------------
  113|    550|		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|    550|	memcpy(&app->aid, &aid, sizeof(struct sc_aid));
  116|       |
  117|    550|	if (asn1_dirrecord[1].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    550|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (117:6): [True: 15, False: 535]
  ------------------
  118|     15|		app->label = strdup((char *) label);
  119|    535|	else
  120|    535|		app->label = NULL;
  121|       |
  122|    550|	if (asn1_dirrecord[2].flags & SC_ASN1_PRESENT && path_len > 0) {
  ------------------
  |  |  147|  1.10k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (122:6): [True: 274, False: 276]
  |  Branch (122:51): [True: 255, False: 19]
  ------------------
  123|       |		/* application path present: ignore AID */
  124|    255|		if (path_len > SC_MAX_PATH_SIZE) {
  ------------------
  |  |   47|    255|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (124:7): [True: 10, False: 245]
  ------------------
  125|     10|			free(app->label);
  126|     10|			free(app);
  127|     10|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "Application path is too long.");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|     10|		}
  129|    245|		memcpy(app->path.value, path, path_len);
  130|    245|		app->path.len = path_len;
  131|    245|		app->path.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    245|#define SC_PATH_TYPE_PATH		2
  ------------------
  132|    245|	}
  133|    295|	else {
  134|       |		/* application path not present: use AID as application path */
  135|    295|		memcpy(app->path.value, aid.value, aid.len);
  136|    295|		app->path.len = aid.len;
  137|    295|		app->path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    295|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  138|    295|	}
  139|       |
  140|    540|	if (asn1_dirrecord[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    540|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (140:6): [True: 47, False: 493]
  ------------------
  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|    493|	} else {
  150|    493|		app->ddo.value = NULL;
  151|    493|		app->ddo.len = 0;
  152|    493|	}
  153|       |
  154|    540|	app->rec_nr = rec_nr;
  155|    540|	card->app[card->app_count] = app;
  156|    540|	card->app_count++;
  157|       |
  158|    540|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 540]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|    540|}

sc_parse_ef_atr:
  139|  1.35k|{
  140|  1.35k|	struct sc_context *ctx = card->ctx;
  141|  1.35k|	struct sc_path path;
  142|  1.35k|	struct sc_file *file = NULL;
  143|  1.35k|	int rv;
  144|  1.35k|	unsigned char *buf = NULL;
  145|  1.35k|	size_t size;
  146|  1.35k|	size_t off = 0;
  147|       |
  148|  1.35k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.35k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.35k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.35k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.35k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.35k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  149|       |
  150|  1.35k|	sc_format_path("3F002F01", &path);
  151|  1.35k|	rv = sc_select_file(card, &path, &file);
  152|  1.35k|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot select EF(ATR) file");
  ------------------
  |  |  184|  1.35k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.35k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.35k|	int _ret = (r); \
  |  |  |  |  178|  1.35k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 786, False: 572]
  |  |  |  |  ------------------
  |  |  |  |  179|    786|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    786|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    786|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    786|		goto err; \
  |  |  |  |  182|    786|	} \
  |  |  |  |  183|  1.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 572]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  153|       |
  154|    572|	if (file->size) {
  ------------------
  |  Branch (154:6): [True: 84, False: 488]
  ------------------
  155|     84|		size = file->size;
  156|    488|	} else {
  157|    488|		size = 1024;
  158|    488|	}
  159|    572|	buf = malloc(size);
  160|    572|	if (!buf) {
  ------------------
  |  Branch (160:6): [True: 0, False: 572]
  ------------------
  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|    572|	rv = sc_read_binary(card, 0, buf, size, 0);
  165|    572|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot read EF(ATR) file");
  ------------------
  |  |  184|    572|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    572|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    572|	int _ret = (r); \
  |  |  |  |  178|    572|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 170, False: 402]
  |  |  |  |  ------------------
  |  |  |  |  179|    170|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    170|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    170|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    170|		goto err; \
  |  |  |  |  182|    170|	} \
  |  |  |  |  183|    572|} 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: 143, False: 259]
  ------------------
  169|    259|	    (card->type == SC_CARD_TYPE_IASECC_CPXCL)) {
  ------------------
  |  Branch (169:6): [True: 43, False: 216]
  ------------------
  170|       |		/* Let's keep the first byte */
  171|    186|		if ((rv > 1) &&
  ------------------
  |  Branch (171:7): [True: 181, False: 5]
  ------------------
  172|    181|		    (buf[0] == ISO7816_II_CATEGORY_TLV))
  ------------------
  |  |   28|    181|#define ISO7816_II_CATEGORY_TLV		0x80
  ------------------
  |  Branch (172:7): [True: 3, False: 178]
  ------------------
  173|      3|			off++;
  174|    186|	}
  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: 21, False: 381]
  |  |  |  |  ------------------
  |  |  |  |  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|    402|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 381]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  177|       |
  178|    381|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    381|#define SC_SUCCESS				0
  ------------------
  179|       |
  180|  1.35k|err:
  181|  1.35k|	sc_file_free(file);
  182|  1.35k|	free(buf);
  183|  1.35k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  1.35k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.35k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.35k|	int _ret = r; \
  |  |  |  |  155|  1.35k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.35k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|    977|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 977, False: 381]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.35k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.35k|	return _ret; \
  |  |  |  |  163|  1.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|  1.35k|}
sc_free_ef_atr:
  187|  16.4k|{
  188|  16.4k|	if (card->ef_atr)
  ------------------
  |  Branch (188:6): [True: 923, False: 15.5k]
  ------------------
  189|    923|		free(card->ef_atr);
  190|       |	card->ef_atr = NULL;
  191|  16.4k|}
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: 6, False: 396]
  |  Branch (47:13): [True: 2, False: 4]
  ------------------
   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: 127, False: 275]
  ------------------
   54|    127|		size_t len = taglen > sizeof(ef_atr.pre_issuing) ? sizeof(ef_atr.pre_issuing) : taglen;
  ------------------
  |  Branch (54:16): [True: 97, False: 30]
  ------------------
   55|       |
   56|    127|		memcpy(ef_atr.pre_issuing, tag, len);
   57|    127|		ef_atr.pre_issuing_len = len;
   58|       |
   59|    127|		sc_log(ctx, "EF.ATR: Pre-Issuing data '%s'", sc_dump_hex(ef_atr.pre_issuing, ef_atr.pre_issuing_len));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   60|    127|	}
   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: 4, False: 398]
  |  Branch (63:13): [True: 3, False: 1]
  ------------------
   64|      3|		ef_atr.df_selection =  *(tag + 0);
   65|      3|		ef_atr.unit_size = *(tag + 1);
   66|      3|		ef_atr.card_capabilities = *(tag + 2);
   67|      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__
  |  |  ------------------
  ------------------
   68|      3|		       "EF.ATR: DF selection %X, unit_size %"SC_FORMAT_LEN_SIZE_T"X, card caps %X",
   69|      3|		       ef_atr.df_selection, ef_atr.unit_size,
   70|      3|		       ef_atr.card_capabilities);
   71|      3|	}
   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: 1, False: 401]
  ------------------
   74|       |		/* Extended Length Information in EF.ATR/INFO */
   75|      1|		tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_EXTENDED_LENGTH, &taglen);
  ------------------
  |  |   41|      1|#define ISO7816_TAG_II_EXTENDED_LENGTH		0x7F66
  ------------------
   76|      1|		if (tag && taglen >= 8) {
  ------------------
  |  Branch (76:7): [True: 0, False: 1]
  |  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|      1|	}
   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: 7, False: 395]
  ------------------
   91|      7|		if (taglen > sizeof(ef_atr.aid.value))
  ------------------
  |  Branch (91:7): [True: 1, False: 6]
  ------------------
   92|      7|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid MF AID size");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   93|      6|		memcpy(ef_atr.aid.value, tag, taglen);
   94|      6|		ef_atr.aid.len = taglen;
   95|      6|		sc_log(ctx, "EF.ATR: AID '%s'", sc_dump_hex(ef_atr.aid.value, ef_atr.aid.len));
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   96|      6|	}
   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: 207, False: 194]
  ------------------
  101|    207|		size_t len = taglen > sizeof(ef_atr.issuer_data) ? sizeof(ef_atr.issuer_data) : taglen;
  ------------------
  |  Branch (101:16): [True: 103, False: 104]
  ------------------
  102|       |
  103|    207|		memcpy(ef_atr.issuer_data, tag, len);
  104|    207|		ef_atr.issuer_data_len = len;
  105|       |
  106|    207|		sc_log(ctx, "EF.ATR: Issuer data '%s'", sc_dump_hex(ef_atr.issuer_data, ef_atr.issuer_data_len));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  107|    207|	}
  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: 42, False: 359]
  ------------------
  111|     42|		sc_log(ctx, "EF.ATR: DER encoded OID %s", sc_dump_hex(tag, taglen));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  112|     42|		tag = sc_asn1_find_tag(ctx, tag, taglen, SC_ASN1_TAG_OBJECT, &taglen);
  ------------------
  |  |  200|     42|#define SC_ASN1_TAG_OBJECT		6
  ------------------
  113|     42|		if (tag)   {
  ------------------
  |  Branch (113:7): [True: 41, False: 1]
  ------------------
  114|     41|			sc_log(ctx, "EF.ATR: OID %s", sc_dump_hex(tag, taglen));
  ------------------
  |  |   71|     41|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  115|     41|			if(sc_asn1_decode_object_id(tag, taglen, &ef_atr.allocation_oid))
  ------------------
  |  Branch (115:7): [True: 20, False: 21]
  ------------------
  116|     41|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  117|     41|		}
  118|     42|	}
  119|       |
  120|    381|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_STATUS_SW, &taglen);
  ------------------
  |  |   39|    381|#define ISO7816_TAG_II_STATUS_SW		0x82
  ------------------
  121|    381|	if (tag && taglen == 2)   {
  ------------------
  |  Branch (121:6): [True: 17, False: 364]
  |  Branch (121:13): [True: 2, False: 15]
  ------------------
  122|      2|		ef_atr.status = *(tag + 0) * 0x100 + *(tag + 1);
  123|      2|		sc_log(ctx, "EF.ATR: status word 0x%X", ef_atr.status);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  124|      2|	}
  125|       |
  126|    381|	if (!card->ef_atr)
  ------------------
  |  Branch (126:6): [True: 375, False: 6]
  ------------------
  127|    375|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  128|       |
  129|    381|	if (!card->ef_atr)
  ------------------
  |  Branch (129:6): [True: 0, False: 381]
  ------------------
  130|    381|		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|    381|	memcpy(card->ef_atr, &ef_atr, sizeof(struct sc_ef_atr));
  133|       |
  134|    381|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 381]
  |  |  |  |  ------------------
  |  |  |  |  157|    381|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    381|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    381|	return _ret; \
  |  |  |  |  163|    381|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    381|}

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

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

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

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

iasecc_sm_initialize:
  270|    218|{
  271|    218|	struct sc_context *ctx = card->ctx;
  272|    218|#ifdef ENABLE_SM
  273|    218|	struct sm_info *sm_info = &card->sm_ctx.info;
  274|    218|	struct sm_cwa_session *cwa_session = &sm_info->session.cwa;
  275|    218|	struct sc_remote_data rdata;
  276|    218|	int rv;
  277|       |
  278|    218|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    218|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    218|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    218|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    218|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 218]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|    218|	strlcpy(sm_info->config_section, card->sm_ctx.config_section, sizeof(sm_info->config_section));
  ------------------
  |  |   43|    218|#define strlcpy _strlcpy
  ------------------
  281|    218|	sm_info->cmd = cmd;
  282|    218|	sm_info->serialnr = card->serialnr;
  283|    218|	sm_info->card_type = card->type;
  284|    218|	sm_info->sm_type = SM_TYPE_CWA14890;
  ------------------
  |  |   39|    218|#define SM_TYPE_CWA14890	0x400
  ------------------
  285|       |
  286|    218|	rv = iasecc_sm_se_mutual_authentication(card, se_num);
  287|    218|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() MUTUAL AUTHENTICATION failed");
  ------------------
  |  |  174|    218|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    218|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    218|	int _ret = (r); \
  |  |  |  |  168|    218|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 218, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    218|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    218|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    218|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    218|		return _ret; \
  |  |  |  |  172|    218|	} \
  |  |  |  |  173|    218|} 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|    218|{
  594|    218|	struct sc_context *ctx = card->ctx;
  595|    218|#ifdef ENABLE_SM
  596|    218|	struct sm_info *sm_info = &card->sm_ctx.info;
  597|    218|	struct sc_remote_data rdata;
  598|    218|	struct iasecc_sm_cmd_update_binary cmd_data;
  599|    218|	int rv;
  600|       |
  601|    218|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    218|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    218|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    218|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    218|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 218]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  602|    218|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  603|    218|	       "SM read binary: acl:%X, offs:%"SC_FORMAT_LEN_SIZE_T"u, count:%"SC_FORMAT_LEN_SIZE_T"u",
  604|    218|	       se_num, offs, count);
  605|       |
  606|    218|	rv = iasecc_sm_initialize(card, se_num, SM_CMD_FILE_READ);
  ------------------
  |  |   56|    218|#define SM_CMD_FILE_READ		0x201
  ------------------
  607|    218|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM INITIALIZE failed");
  ------------------
  |  |  174|    218|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    218|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    218|	int _ret = (r); \
  |  |  |  |  168|    218|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 218, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    218|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    218|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    218|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    218|		return _ret; \
  |  |  |  |  172|    218|	} \
  |  |  |  |  173|    218|} 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|    218|{
  223|    218|	struct sc_context *ctx = card->ctx;
  224|    218|	struct sm_info *sm_info = &card->sm_ctx.info;
  225|    218|	struct iasecc_se_info se;
  226|    218|	struct sc_crt *crt =  &sm_info->session.cwa.params.crt_at;
  227|    218|	struct sc_apdu apdu;
  228|    218|	unsigned char sbuf[0x100];
  229|    218|	int rv, offs;
  230|       |
  231|    218|	memset(&se, 0, sizeof(se));
  232|       |
  233|    218|	se.reference = se_num;
  234|    218|	crt->usage = IASECC_UQB_AT_MUTUAL_AUTHENTICATION;
  ------------------
  |  |  127|    218|#define IASECC_UQB_AT_MUTUAL_AUTHENTICATION	0xC0
  ------------------
  235|    218|	crt->tag = IASECC_CRT_TAG_AT;
  ------------------
  |  |  104|    218|#define IASECC_CRT_TAG_AT	0xA4
  ------------------
  236|       |
  237|    218|	rv = iasecc_se_get_info(card, &se);
  238|    218|	LOG_TEST_RET(ctx, rv, "Get SE info error");
  ------------------
  |  |  174|    218|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    218|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    218|	int _ret = (r); \
  |  |  |  |  168|    218|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 176, False: 42]
  |  |  |  |  ------------------
  |  |  |  |  169|    176|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    176|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    176|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    176|		return _ret; \
  |  |  |  |  172|    176|	} \
  |  |  |  |  173|    218|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 42]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  239|       |
  240|     42|	rv = iasecc_se_get_crt(card, &se, crt);
  241|     42|	sc_file_free(se.df);
  242|     42|	LOG_TEST_RET(ctx, rv, "Cannot get authentication CRT");
  ------------------
  |  |  174|     42|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     42|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     42|	int _ret = (r); \
  |  |  |  |  168|     42|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 42, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     42|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     42|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     42|		return _ret; \
  |  |  |  |  172|     42|	} \
  |  |  |  |  173|     42|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  67.8k|{
   37|  67.8k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (37:6): [True: 0, False: 67.8k]
  |  Branch (37:22): [True: 0, False: 67.8k]
  ------------------
   38|      0|		return;
   39|      0|	}
   40|       |
   41|  67.8k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (41:6): [True: 586, False: 67.3k]
  ------------------
   42|       |		/* The lower layers will automatically do chaining */
   43|    586|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    586|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   44|    586|	}
   45|       |
   46|  67.8k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (46:6): [True: 2.87k, False: 65.0k]
  ------------------
   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|  2.87k|		apdu->le = sc_get_max_recv_size(card);
   50|  2.87k|	}
   51|  67.8k|}
encode_do_data:
  177|  16.1k|{
  178|  16.1k|	unsigned char offset_buffer[2];
  179|  16.1k|	size_t offset_buffer_len = sizeof offset_buffer;
  180|  16.1k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  181|  16.1k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  182|       |
  183|  16.1k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (183:6): [True: 0, False: 16.1k]
  ------------------
  184|  16.1k|		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|  16.1k|	offset_buffer[0] = (u8) (idx >> 8);
  186|  16.1k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  187|  16.1k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  188|       |
  189|  16.1k|	if (data && data_len) {
  ------------------
  |  Branch (189:6): [True: 0, False: 16.1k]
  |  Branch (189:14): [True: 0, False: 0]
  ------------------
  190|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  191|  16.1k|	} else {
  192|  16.1k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  193|  16.1k|	}
  194|       |
  195|  16.1k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  16.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  16.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  16.1k|	int _ret = (r); \
  |  |  |  |  168|  16.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 16.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  16.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|  16.1k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  197|  16.1k|			"sc_asn1_encode() failed");
  198|       |
  199|  16.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  200|  16.1k|}
decode_do_data:
  205|  13.1k|{
  206|  13.1k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  207|  13.1k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  208|       |
  209|  13.1k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  210|  13.1k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  211|       |
  212|  13.1k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  13.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  13.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  13.1k|	int _ret = (r); \
  |  |  |  |  168|  13.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.43k, False: 11.7k]
  |  |  |  |  ------------------
  |  |  |  |  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|  13.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|  11.7k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  214|  11.7k|			"sc_asn1_decode() failed");
  215|       |
  216|  11.7k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  11.7k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (216:6): [True: 9.87k, False: 1.87k]
  ------------------
  217|  9.87k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  9.87k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  218|       |
  219|  1.87k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.87k|#define SC_SUCCESS				0
  ------------------
  220|  11.7k|}
iso7816_build_pin_apdu:
 1189|  8.35k|{
 1190|  8.35k|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1191|  8.35k|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  8.35k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1192|       |
 1193|  8.35k|	switch (data->pin_type) {
 1194|  8.35k|	case SC_AC_CHV:
  ------------------
  |  |  151|  8.35k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1194:2): [True: 8.35k, False: 0]
  ------------------
 1195|       |		/* fall through */
 1196|  8.35k|	case SC_AC_SESSION:
  ------------------
  |  |  159|  8.35k|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1196:2): [True: 0, False: 8.35k]
  ------------------
 1197|  8.35k|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|  8.35k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1197:2): [True: 0, False: 8.35k]
  ------------------
 1198|  8.35k|		break;
 1199|      0|	default:
  ------------------
  |  Branch (1199:2): [True: 0, False: 8.35k]
  ------------------
 1200|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1201|  8.35k|	}
 1202|       |
 1203|  8.35k|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  429|  8.35k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1203:6): [True: 1.34k, False: 7.00k]
  ------------------
 1204|  1.34k|		pad = 1;
 1205|  8.35k|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  428|  8.35k|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1205:6): [True: 0, False: 8.35k]
  ------------------
 1206|      0|		use_pin_pad = 1;
 1207|       |
 1208|  8.35k|	data->pin1.offset = 5;
 1209|       |
 1210|  8.35k|	switch (data->cmd) {
 1211|  1.00k|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|  1.00k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1211:2): [True: 1.00k, False: 7.34k]
  ------------------
 1212|  1.00k|		ins = 0x20;
 1213|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1214|  1.00k|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1214:7): [True: 0, False: 1.00k]
  |  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|  1.00k|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1216:7): [True: 18, False: 989]
  ------------------
 1217|     18|			return r;
 1218|    989|		len = r;
 1219|    989|		break;
 1220|    282|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|    282|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1220:2): [True: 282, False: 8.06k]
  ------------------
 1221|    282|		ins = 0x24;
 1222|    282|		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: 274, False: 8]
  |  Branch (1222:31): [True: 0, False: 8]
  |  Branch (1222:46): [True: 0, False: 0]
  ------------------
 1223|    274|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1223:8): [True: 11, False: 263]
  ------------------
 1224|     11|				return r;
 1225|    263|			len += r;
 1226|    263|		}
 1227|      8|		else {
 1228|       |			/* implicit test */
 1229|      8|			p1 = 1;
 1230|      8|		}
 1231|       |
 1232|    271|		data->pin2.offset = data->pin1.offset + len;
 1233|    271|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1233:7): [True: 18, False: 253]
  ------------------
 1234|     18|			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|    253|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1238:7): [True: 245, False: 8]
  |  Branch (1238:25): [True: 0, False: 245]
  ------------------
 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|    253|		len += r;
 1243|    253|		break;
 1244|    368|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|    368|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1244:2): [True: 368, False: 7.98k]
  ------------------
 1245|    368|		ins = 0x2C;
 1246|    368|		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: 362, False: 6]
  |  Branch (1246:31): [True: 0, False: 6]
  |  Branch (1246:46): [True: 0, False: 0]
  ------------------
 1247|    362|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1247:8): [True: 6, False: 356]
  ------------------
 1248|      6|				return r;
 1249|    356|			len += r;
 1250|    356|		} else {
 1251|      6|			p1 |= 0x02;
 1252|      6|		}
 1253|       |
 1254|    362|		if (data->pin2.len != 0 || use_pin_pad) {
  ------------------
  |  Branch (1254:7): [True: 362, False: 0]
  |  Branch (1254:30): [True: 0, False: 0]
  ------------------
 1255|    362|			data->pin2.offset = data->pin1.offset + len;
 1256|    362|			if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1256:8): [True: 15, False: 347]
  ------------------
 1257|     15|				return r;
 1258|    347|			len += r;
 1259|    347|		} else {
 1260|      0|			p1 |= 0x01;
 1261|      0|		}
 1262|    347|		if (p1 == 0x03) {
  ------------------
  |  Branch (1262:7): [True: 0, False: 347]
  ------------------
 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|    347|		break;
 1267|  6.69k|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|  6.69k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1267:2): [True: 6.69k, False: 1.65k]
  ------------------
 1268|  6.69k|		ins = 0x20;
 1269|       |		/* No data to send or to receive */
 1270|  6.69k|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|  6.69k|#define SC_APDU_CASE_1			0x01
  ------------------
 1271|  6.69k|		break;
 1272|      0|	default:
  ------------------
  |  Branch (1272:2): [True: 0, False: 8.35k]
  ------------------
 1273|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1274|  8.35k|	}
 1275|       |
 1276|  8.28k|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1277|  8.28k|	apdu->lc = len;
 1278|  8.28k|	apdu->datalen = len;
 1279|  8.28k|	apdu->data = buf;
 1280|  8.28k|	apdu->resplen = 0;
 1281|       |
 1282|  8.28k|	return 0;
 1283|  8.35k|}
iso7816_select_aid:
 1401|  21.2k|{
 1402|  21.2k|	struct sc_context *ctx = card->ctx;
 1403|  21.2k|	struct sc_apdu apdu;
 1404|  21.2k|	int rv;
 1405|       |
 1406|  21.2k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  21.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  21.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  21.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 21.2k]
  |  |  ------------------
  ------------------
 1407|       |
 1408|  21.2k|	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.54k|#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|  13.6k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1408:30): [True: 7.54k, False: 13.6k]
  |  Branch (1408:102): [True: 7.54k, False: 13.6k]
  ------------------
 1409|  21.2k|	apdu.lc = reqlen;
 1410|  21.2k|	apdu.data = req;
 1411|  21.2k|	apdu.datalen = reqlen;
 1412|  21.2k|	apdu.resp = resp;
 1413|  21.2k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1413:17): [True: 7.54k, False: 13.6k]
  ------------------
 1414|  21.2k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1414:12): [True: 7.54k, False: 13.6k]
  ------------------
 1415|       |
 1416|  21.2k|	rv = sc_transmit_apdu(card, &apdu);
 1417|  21.2k|	if (resplen)
  ------------------
  |  Branch (1417:6): [True: 13.6k, False: 7.54k]
  ------------------
 1418|  13.6k|		*resplen = apdu.resplen;
 1419|  21.2k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  21.2k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  21.2k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  21.2k|	int _ret = (r); \
  |  |  |  |  168|  21.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 229, False: 21.0k]
  |  |  |  |  ------------------
  |  |  |  |  169|    229|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    229|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    229|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    229|		return _ret; \
  |  |  |  |  172|    229|	} \
  |  |  |  |  173|  21.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 21.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1420|       |
 1421|  21.0k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1422|  21.0k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  21.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  21.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  21.0k|	int _ret = r; \
  |  |  |  |  155|  21.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  21.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|  15.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 15.5k, False: 5.46k]
  |  |  |  |  ------------------
  |  |  |  |  157|  21.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  21.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|  21.0k|	return _ret; \
  |  |  |  |  163|  21.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1423|  21.0k|}
sc_get_iso7816_driver:
 1491|   571k|{
 1492|   571k|	return &iso_driver;
 1493|   571k|}
iso7816.c:no_match:
 1437|  7.59k|{
 1438|  7.59k|	return 0;
 1439|  7.59k|}
iso7816.c:iso7816_read_record:
  225|  33.2k|{
  226|  33.2k|	struct sc_apdu apdu;
  227|  33.2k|	int r;
  228|       |	/* XXX maybe use some bigger buffer */
  229|  33.2k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  230|  33.2k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  231|  33.2k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  232|       |
  233|  33.2k|	if (rec_nr > 0xFF)
  ------------------
  |  Branch (233:6): [True: 28, False: 33.2k]
  ------------------
  234|  33.2k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|       |
  236|  33.2k|	if (idx == 0) {
  ------------------
  |  Branch (236:6): [True: 17.0k, False: 16.1k]
  ------------------
  237|  17.0k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  17.0k|#define SC_APDU_CASE_2			0x22
  ------------------
  238|  17.0k|		apdu.le = count;
  239|  17.0k|		apdu.resplen = count;
  240|  17.0k|		apdu.resp = buf;
  241|  17.0k|	} else {
  242|  16.1k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  243|  16.1k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  16.1k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  16.1k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  16.1k|	int _ret = (r); \
  |  |  |  |  178|  16.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 16.1k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  16.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 16.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|       |
  245|  16.1k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  16.1k|#define SC_APDU_CASE_4			0x24
  ------------------
  246|  16.1k|		apdu.lc = encoded_data_len;
  247|  16.1k|		apdu.datalen = encoded_data_len;
  248|  16.1k|		apdu.data = encoded_data;
  249|  16.1k|		apdu.le = sizeof resp;
  250|  16.1k|		apdu.resplen = sizeof resp;
  251|  16.1k|		apdu.resp = resp;
  252|  16.1k|	}
  253|  33.2k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1300|  33.2k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  254|  33.2k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1305|  33.2k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (254:6): [True: 33.2k, False: 0]
  ------------------
  255|  33.2k|		apdu.p2 |= 0x04;
  256|       |
  257|  33.2k|	iso7816_fixup_transceive_length(card, &apdu);
  258|  33.2k|	r = sc_transmit_apdu(card, &apdu);
  259|  33.2k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  33.2k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  33.2k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  33.2k|	int _ret = (r); \
  |  |  |  |  178|  33.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1.53k, False: 31.6k]
  |  |  |  |  ------------------
  |  |  |  |  179|  1.53k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.53k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  1.53k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  1.53k|		goto err; \
  |  |  |  |  182|  1.53k|	} \
  |  |  |  |  183|  33.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 31.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|  31.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  261|  31.6k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  31.6k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  31.6k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  31.6k|	int _ret = (r); \
  |  |  |  |  178|  31.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 3.18k, False: 28.5k]
  |  |  |  |  ------------------
  |  |  |  |  179|  3.18k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.18k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  3.18k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  3.18k|		goto err; \
  |  |  |  |  182|  3.18k|	} \
  |  |  |  |  183|  31.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 28.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|       |
  263|  28.5k|	if (idx == 0) {
  ------------------
  |  Branch (263:6): [True: 15.3k, False: 13.1k]
  ------------------
  264|  15.3k|		r = (int)apdu.resplen;
  265|  15.3k|	} else {
  266|  13.1k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  267|  13.1k|				&decoded_data, &decoded_data_len);
  268|  13.1k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  13.1k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  13.1k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  13.1k|	int _ret = (r); \
  |  |  |  |  178|  13.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 11.3k, False: 1.87k]
  |  |  |  |  ------------------
  |  |  |  |  179|  11.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  11.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  11.3k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  11.3k|		goto err; \
  |  |  |  |  182|  11.3k|	} \
  |  |  |  |  183|  13.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.87k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  1.87k|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (269:7): [True: 1.61k, False: 262]
  ------------------
  270|  1.61k|			count = decoded_data_len;
  271|  1.61k|		}
  272|  1.87k|		memcpy(buf, decoded_data, count);
  273|  1.87k|		r = (int)count;
  274|  1.87k|	}
  275|       |
  276|  33.2k|err:
  277|  33.2k|	free(encoded_data);
  278|  33.2k|	free(decoded_data);
  279|  33.2k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  33.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  33.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  33.2k|	int _ret = r; \
  |  |  |  |  155|  33.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.7k, False: 16.4k]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  16.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16.0k, False: 743]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.7k|	} else { \
  |  |  |  |  159|  16.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.4k|	} \
  |  |  |  |  162|  33.2k|	return _ret; \
  |  |  |  |  163|  33.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|  33.2k|}
iso7816.c:iso7816_select_file:
  631|  51.8k|{
  632|  51.8k|	struct sc_context *ctx;
  633|  51.8k|	struct sc_apdu apdu;
  634|  51.8k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  635|  51.8k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  636|  51.8k|	int r, pathtype;
  637|  51.8k|	size_t pathlen;
  638|  51.8k|	int select_mf = 0;
  639|  51.8k|	struct sc_file *file = NULL;
  640|  51.8k|	const u8 *buffer;
  641|  51.8k|	size_t buffer_len;
  642|  51.8k|	unsigned int cla, tag;
  643|       |
  644|  51.8k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (644:6): [True: 0, False: 51.8k]
  |  Branch (644:22): [True: 0, False: 51.8k]
  ------------------
  645|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  646|      0|	}
  647|  51.8k|	ctx = card->ctx;
  648|  51.8k|	memcpy(path, in_path->value, in_path->len);
  649|  51.8k|	pathlen = in_path->len;
  650|  51.8k|	pathtype = in_path->type;
  651|       |
  652|  51.8k|	if (in_path->aid.len) {
  ------------------
  |  Branch (652:6): [True: 1.83k, False: 50.0k]
  ------------------
  653|  1.83k|		if (!pathlen) {
  ------------------
  |  Branch (653:7): [True: 1.35k, False: 480]
  ------------------
  654|  1.35k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  655|  1.35k|			pathlen = in_path->aid.len;
  656|  1.35k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.35k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  657|  1.35k|		} else {
  658|       |			/* First, select the application */
  659|    480|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|    480|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  660|    480|			apdu.data = in_path->aid.value;
  661|    480|			apdu.datalen = in_path->aid.len;
  662|    480|			apdu.lc = in_path->aid.len;
  663|       |
  664|    480|			r = sc_transmit_apdu(card, &apdu);
  665|    480|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    480|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    480|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    480|	int _ret = (r); \
  |  |  |  |  168|    480|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 477]
  |  |  |  |  ------------------
  |  |  |  |  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|    480|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 477]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  666|    477|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  667|    477|			if (r)
  ------------------
  |  Branch (667:8): [True: 358, False: 119]
  ------------------
  668|    477|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    358|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    358|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    358|	int _ret = r; \
  |  |  |  |  155|    358|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 358, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    358|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    358|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 358, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    358|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    358|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    358|	return _ret; \
  |  |  |  |  163|    358|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  669|       |
  670|    119|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    238|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (670:8): [True: 119, 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|    119|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|    119|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  673|    119|		}
  674|  1.83k|	}
  675|       |
  676|  51.4k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  51.4k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  677|       |
  678|  51.4k|	switch (pathtype) {
  679|  10.4k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  10.4k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (679:2): [True: 10.4k, False: 41.0k]
  ------------------
  680|  10.4k|		apdu.p1 = 0;
  681|  10.4k|		if (pathlen != 2)
  ------------------
  |  Branch (681:7): [True: 0, False: 10.4k]
  ------------------
  682|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  683|  10.4k|		break;
  684|  22.2k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  22.2k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (684:2): [True: 22.2k, False: 29.2k]
  ------------------
  685|  22.2k|		apdu.p1 = 4;
  686|  22.2k|		break;
  687|  18.5k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  18.5k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (687:2): [True: 18.5k, False: 32.9k]
  ------------------
  688|  18.5k|		apdu.p1 = 8;
  689|  18.5k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (689:7): [True: 18.4k, False: 100]
  |  Branch (689:23): [True: 12.7k, False: 5.70k]
  ------------------
  690|  12.7k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (690:8): [True: 3.43k, False: 9.32k]
  ------------------
  691|  3.43k|				select_mf = 1;
  692|  3.43k|				apdu.p1 = 0;
  693|  3.43k|				break;
  694|  3.43k|			}
  695|  9.32k|			path += 2;
  696|  9.32k|			pathlen -= 2;
  697|  9.32k|		}
  698|  15.1k|		break;
  699|  15.1k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|    119|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (699:2): [True: 119, False: 51.3k]
  ------------------
  700|    119|		apdu.p1 = 9;
  701|    119|		break;
  702|    118|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    118|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (702:2): [True: 118, False: 51.3k]
  ------------------
  703|    118|		apdu.p1 = 3;
  704|    118|		pathlen = 0;
  705|    118|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|    118|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  706|    118|		break;
  707|      0|	default:
  ------------------
  |  Branch (707:2): [True: 0, False: 51.4k]
  ------------------
  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|  51.4k|	}
  710|  51.4k|	apdu.lc = pathlen;
  711|  51.4k|	apdu.data = path;
  712|  51.4k|	apdu.datalen = pathlen;
  713|       |
  714|  51.4k|	if (file_out != NULL) {
  ------------------
  |  Branch (714:6): [True: 33.4k, False: 18.0k]
  ------------------
  715|  33.4k|		apdu.p2 = 0;		/* first record, return FCI */
  716|  33.4k|		apdu.resp = buf;
  717|  33.4k|		apdu.resplen = sizeof(buf);
  718|  33.4k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (718:13): [True: 968, False: 32.4k]
  ------------------
  719|  33.4k|	}
  720|  18.0k|	else {
  721|  18.0k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  722|  18.0k|		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
              		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  36.1k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (722:14): [True: 0, False: 18.0k]
  ------------------
  723|  18.0k|	}
  724|       |
  725|  51.4k|	r = sc_transmit_apdu(card, &apdu);
  726|  51.4k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  51.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  51.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  51.4k|	int _ret = (r); \
  |  |  |  |  168|  51.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 450, False: 51.0k]
  |  |  |  |  ------------------
  |  |  |  |  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|  51.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 51.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  727|  51.0k|	if (file_out == NULL) {
  ------------------
  |  Branch (727:6): [True: 18.0k, False: 32.9k]
  ------------------
  728|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  729|  18.0k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  730|  18.0k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (730:7): [True: 147, False: 17.9k]
  |  Branch (730:27): [True: 25, False: 122]
  ------------------
  731|     25|			apdu.p2 = 0x00;
  732|     25|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     25|#define SC_SUCCESS				0
  ------------------
  |  Branch (732:8): [True: 15, False: 10]
  ------------------
  733|     15|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  734|     25|		}
  735|  18.0k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (735:7): [True: 0, False: 18.0k]
  ------------------
  736|  18.0k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  737|  18.0k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  18.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.0k|	int _ret = r; \
  |  |  |  |  155|  18.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  18.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.8k, False: 5.23k]
  |  |  |  |  ------------------
  |  |  |  |  157|  18.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  18.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  18.0k|	return _ret; \
  |  |  |  |  163|  18.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  738|  18.0k|	}
  739|       |
  740|  32.9k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  741|  32.9k|	if (r)
  ------------------
  |  Branch (741:6): [True: 18.2k, False: 14.7k]
  ------------------
  742|  32.9k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  18.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.2k|	int _ret = r; \
  |  |  |  |  155|  18.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  18.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  18.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  18.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  18.2k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  18.2k|	return _ret; \
  |  |  |  |  163|  18.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  743|       |
  744|  14.7k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (744:6): [True: 14.7k, False: 0]
  |  Branch (744:18): [True: 2.70k, False: 12.0k]
  ------------------
  745|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  746|  2.70k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  2.22k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (746:7): [True: 478, False: 2.22k]
  |  Branch (746:20): [True: 1.32k, False: 903]
  ------------------
  747|  1.80k|			file = sc_file_new();
  748|  1.80k|			if (file == NULL)
  ------------------
  |  Branch (748:8): [True: 0, False: 1.80k]
  ------------------
  749|  1.80k|				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.80k|			file->path = *in_path;
  751|       |
  752|  1.80k|			*file_out = file;
  753|  1.80k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.80k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.80k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.80k|	int _ret = r; \
  |  |  |  |  155|  1.80k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.80k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.80k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.80k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.80k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.80k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.80k|	return _ret; \
  |  |  |  |  163|  1.80k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  754|  1.80k|		}
  755|  2.70k|	}
  756|       |
  757|  12.9k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (757:6): [True: 973, False: 12.0k]
  ------------------
  758|  12.9k|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    973|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    973|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    973|	int _ret = r; \
  |  |  |  |  155|    973|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 973, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    973|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    973|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 973, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    973|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    973|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    973|	return _ret; \
  |  |  |  |  163|    973|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  759|  12.0k|	switch (apdu.resp[0]) {
  760|  10.9k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  10.9k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (760:2): [True: 10.9k, False: 1.01k]
  ------------------
  761|  11.6k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  11.6k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (761:2): [True: 704, False: 11.3k]
  ------------------
  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.7k, False: 912]
  ------------------
  773|  10.7k|			card->ops->process_fci(card, file, buffer, buffer_len);
  774|  11.6k|		*file_out = file;
  775|  11.6k|		break;
  776|    109|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (776:2): [True: 109, False: 11.8k]
  ------------------
  777|    109|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    109|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    109|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    109|	int _ret = r; \
  |  |  |  |  155|    109|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 109, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    109|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    109|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 109, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    109|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    109|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    109|	return _ret; \
  |  |  |  |  163|    109|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|    204|	default:
  ------------------
  |  Branch (778:2): [True: 204, False: 11.8k]
  ------------------
  779|    204|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  36.0k|{
  907|  36.0k|	struct sc_apdu apdu = {0};
  908|  36.0k|	int r;
  909|  36.0k|	size_t rlen;
  910|       |
  911|       |	/* request at most max_recv_size bytes */
  912|  36.0k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (912:6): [True: 974, False: 35.0k]
  ------------------
  913|    974|		rlen = sc_get_max_recv_size(card);
  914|  35.0k|	else
  915|  35.0k|		rlen = *count;
  916|       |
  917|  36.0k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|  36.0k|#define SC_APDU_CASE_2			0x22
  ------------------
  918|  36.0k|	apdu.le      = rlen;
  919|  36.0k|	apdu.resplen = rlen;
  920|  36.0k|	apdu.resp    = buf;
  921|       |	/* don't call GET RESPONSE recursively */
  922|  36.0k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  36.0k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  923|       |
  924|  36.0k|	r = sc_transmit_apdu(card, &apdu);
  925|  36.0k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  36.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  36.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  36.0k|	int _ret = (r); \
  |  |  |  |  168|  36.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 431, False: 35.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|    431|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    431|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    431|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    431|		return _ret; \
  |  |  |  |  172|    431|	} \
  |  |  |  |  173|  36.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 35.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  926|       |
  927|  35.5k|	*count = apdu.resplen;
  928|       |
  929|  35.5k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (929:6): [True: 7.64k, False: 27.9k]
  ------------------
  930|  7.64k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  7.64k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.64k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.64k|	int _ret = r; \
  |  |  |  |  155|  7.64k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.64k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.64k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.65k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.65k, False: 3.99k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.64k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.64k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.64k|	return _ret; \
  |  |  |  |  163|  7.64k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  931|  7.64k|	}
  932|  27.9k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (932:6): [True: 15.0k, False: 12.8k]
  |  Branch (932:26): [True: 14.8k, False: 189]
  ------------------
  933|  14.8k|		r = 0;					/* no more data to read */
  934|  13.0k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (934:11): [True: 7.91k, False: 5.14k]
  ------------------
  935|  7.91k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (935:7): [True: 3.64k, False: 4.27k]
  ------------------
  936|  5.14k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (936:11): [True: 1.44k, False: 3.69k]
  |  Branch (936:31): [True: 1.33k, False: 113]
  ------------------
  937|  1.33k|		r = 0; /* Le not reached but file/record ended */
  938|  3.81k|	else
  939|  3.81k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  940|       |
  941|  27.9k|	return r;
  942|  35.5k|}
iso7816.c:iso7816_restore_security_env:
 1078|     40|{
 1079|     40|	struct sc_apdu apdu;
 1080|     40|	int r;
 1081|       |
 1082|     40|	if (card == NULL) {
  ------------------
  |  Branch (1082:6): [True: 0, False: 40]
  ------------------
 1083|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1084|      0|	}
 1085|       |
 1086|     40|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0xF3, se_num);
  ------------------
  |  |  291|     40|#define SC_APDU_CASE_1			0x01
  ------------------
 1087|       |
 1088|     40|	r = sc_transmit_apdu(card, &apdu);
 1089|     40|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     40|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     40|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     40|	int _ret = (r); \
  |  |  |  |  168|     40|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     40|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1090|     30|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1091|     30|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     30|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     30|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     30|	int _ret = (r); \
  |  |  |  |  168|     30|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1092|       |
 1093|     16|	return r;
 1094|     30|}
iso7816.c:iso7816_set_security_env:
  983|  1.49k|{
  984|  1.49k|	struct sc_apdu apdu;
  985|  1.49k|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  986|  1.49k|	u8 *p;
  987|  1.49k|	int r, locked = 0;
  988|       |
  989|  1.49k|	if (card == NULL || env == NULL) {
  ------------------
  |  Branch (989:6): [True: 0, False: 1.49k]
  |  Branch (989:22): [True: 0, False: 1.49k]
  ------------------
  990|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  991|      0|	}
  992|  1.49k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0);
  ------------------
  |  |  293|  1.49k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  993|  1.49k|	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.49k]
  ------------------
  995|      0|		apdu.p2 = 0xA4;
  996|      0|		break;
  997|    372|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   56|    372|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (997:2): [True: 372, False: 1.11k]
  ------------------
  998|    372|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   59|    372|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (998:2): [True: 0, False: 1.49k]
  ------------------
  999|    372|		apdu.p2 = 0xB8;
 1000|    372|		break;
 1001|  1.11k|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   57|  1.11k|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1001:2): [True: 1.11k, False: 372]
  ------------------
 1002|  1.11k|		apdu.p2 = 0xB6;
 1003|  1.11k|		break;
 1004|      0|	default:
  ------------------
  |  Branch (1004:2): [True: 0, False: 1.49k]
  ------------------
 1005|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1006|  1.49k|	}
 1007|  1.49k|	p = sbuf;
 1008|  1.49k|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   65|  1.49k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1008:6): [True: 1.01k, False: 473]
  ------------------
 1009|  1.01k|		*p++ = 0x80;	/* algorithm reference */
 1010|  1.01k|		*p++ = 0x01;
 1011|  1.01k|		*p++ = env->algorithm_ref & 0xFF;
 1012|  1.01k|	}
 1013|  1.49k|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   66|  1.49k|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1013:6): [True: 0, False: 1.49k]
  ------------------
 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.49k|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   67|  1.49k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1024:6): [True: 1.49k, False: 0]
  ------------------
 1025|  1.49k|		if (sizeof(sbuf) - (p - sbuf) < env->key_ref_len + 2)
  ------------------
  |  Branch (1025:7): [True: 0, False: 1.49k]
  ------------------
 1026|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1027|       |
 1028|  1.49k|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   68|  1.49k|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1028:7): [True: 0, False: 1.49k]
  ------------------
 1029|      0|			*p++ = 0x83;
 1030|  1.49k|		else
 1031|  1.49k|			*p++ = 0x84;
 1032|  1.49k|		if (env->key_ref_len > SC_MAX_KEYREF_SIZE)
  ------------------
  |  |   53|  1.49k|#define SC_MAX_KEYREF_SIZE		8
  ------------------
  |  Branch (1032:7): [True: 0, False: 1.49k]
  ------------------
 1033|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1034|  1.49k|		*p++ = env->key_ref_len & 0xFF;
 1035|  1.49k|		memcpy(p, env->key_ref, env->key_ref_len);
 1036|  1.49k|		p += env->key_ref_len;
 1037|  1.49k|	}
 1038|  1.49k|	r = (int)(p - sbuf);
 1039|  1.49k|	apdu.lc = r;
 1040|  1.49k|	apdu.datalen = r;
 1041|  1.49k|	apdu.data = sbuf;
 1042|  1.49k|	if (se_num > 0) {
  ------------------
  |  Branch (1042:6): [True: 0, False: 1.49k]
  ------------------
 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.49k|	if (apdu.datalen != 0) {
  ------------------
  |  Branch (1047:6): [True: 1.49k, False: 0]
  ------------------
 1048|  1.49k|		r = sc_transmit_apdu(card, &apdu);
 1049|  1.49k|		if (r) {
  ------------------
  |  Branch (1049:7): [True: 20, False: 1.47k]
  ------------------
 1050|     20|			sc_log(card->ctx, "%s: APDU transmit failed", sc_strerror(r));
  ------------------
  |  |   71|     20|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1051|     20|			goto err;
 1052|     20|		}
 1053|  1.47k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1054|  1.47k|		if (r) {
  ------------------
  |  Branch (1054:7): [True: 1.16k, False: 305]
  ------------------
 1055|  1.16k|			sc_log(card->ctx, "%s: Card returned error", sc_strerror(r));
  ------------------
  |  |   71|  1.16k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1056|  1.16k|			goto err;
 1057|  1.16k|		}
 1058|  1.47k|	}
 1059|    305|	if (se_num <= 0) {
  ------------------
  |  Branch (1059:6): [True: 305, False: 0]
  ------------------
 1060|    305|		r = SC_SUCCESS;
  ------------------
  |  |   28|    305|#define SC_SUCCESS				0
  ------------------
 1061|    305|		goto err;
 1062|    305|	}
 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.49k|err:
 1070|  1.49k|	if (locked)
  ------------------
  |  Branch (1070:6): [True: 0, False: 1.49k]
  ------------------
 1071|      0|		sc_unlock(card);
 1072|  1.49k|	return r;
 1073|      0|}
iso7816.c:iso7816_decipher:
 1142|     29|{
 1143|     29|	int r;
 1144|     29|	struct sc_apdu apdu;
 1145|     29|	u8 *sbuf = NULL;
 1146|       |
 1147|     29|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1147:6): [True: 0, False: 29]
  |  Branch (1147:22): [True: 0, False: 29]
  |  Branch (1147:40): [True: 0, False: 29]
  ------------------
 1148|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1149|      0|	}
 1150|     29|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     29|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     29|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     29|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     29|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 29]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1151|     29|	sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1152|     29|	       "ISO7816 decipher: in-len %"SC_FORMAT_LEN_SIZE_T"u, out-len %"SC_FORMAT_LEN_SIZE_T"u",
 1153|     29|	       crgram_len, outlen);
 1154|       |
 1155|     29|	sbuf = malloc(crgram_len + 1);
 1156|     29|	if (sbuf == NULL)
  ------------------
  |  Branch (1156:6): [True: 0, False: 29]
  ------------------
 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|     29|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x80, 0x86);
  ------------------
  |  |  303|     29|#define SC_APDU_CASE_4			0x24
  ------------------
 1163|     29|	apdu.resp    = out;
 1164|     29|	apdu.resplen = outlen;
 1165|     29|	apdu.le      = outlen;
 1166|       |
 1167|     29|	sbuf[0] = 0; /* padding indicator byte, 0x00 = No further indication */
 1168|     29|	memcpy(sbuf + 1, crgram, crgram_len);
 1169|     29|	apdu.data = sbuf;
 1170|     29|	apdu.lc = crgram_len + 1;
 1171|     29|	apdu.datalen = crgram_len + 1;
 1172|       |
 1173|     29|	iso7816_fixup_transceive_length(card, &apdu);
 1174|     29|	r = sc_transmit_apdu(card, &apdu);
 1175|     29|	sc_mem_clear(sbuf, crgram_len + 1);
 1176|     29|	free(sbuf);
 1177|     29|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     29|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     29|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     29|	int _ret = (r); \
  |  |  |  |  168|     29|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  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|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1178|       |
 1179|     22|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1179:6): [True: 14, False: 8]
  |  Branch (1179:26): [True: 11, False: 3]
  ------------------
 1180|     22|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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|      8|	} else { \
  |  |  |  |  159|      8|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      8|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      8|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1181|     11|	else
 1182|     22|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1183|     22|}
iso7816.c:iso7816_compute_signature:
 1101|    131|{
 1102|    131|	int r;
 1103|    131|	struct sc_apdu apdu;
 1104|       |
 1105|    131|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (1105:6): [True: 0, False: 131]
  |  Branch (1105:22): [True: 0, False: 131]
  |  Branch (1105:38): [True: 0, False: 131]
  ------------------
 1106|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1107|      0|	}
 1108|    131|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    131|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    131|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    131|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    131|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 131]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1109|    131|	sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1110|    131|	       "ISO7816 compute signature: in-len %"SC_FORMAT_LEN_SIZE_T"u, out-len %"SC_FORMAT_LEN_SIZE_T"u",
 1111|    131|	       datalen, outlen);
 1112|       |
 1113|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1114|       |	 * P1:  0x9E  Resp: Digital Signature
 1115|       |	 * P2:  0x9A  Cmd: Input for Digital Signature */
 1116|    131|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  303|    131|#define SC_APDU_CASE_4			0x24
  ------------------
 1117|    131|	apdu.resp = out;
 1118|    131|	apdu.resplen = outlen;
 1119|    131|	apdu.le = outlen;
 1120|       |
 1121|    131|	apdu.data = data;
 1122|    131|	apdu.lc = datalen;
 1123|    131|	apdu.datalen = datalen;
 1124|       |
 1125|    131|	iso7816_fixup_transceive_length(card, &apdu);
 1126|    131|	r = sc_transmit_apdu(card, &apdu);
 1127|    131|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    131|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    131|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    131|	int _ret = (r); \
  |  |  |  |  168|    131|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 31, False: 100]
  |  |  |  |  ------------------
  |  |  |  |  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|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 100]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1128|    100|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1128:6): [True: 69, False: 31]
  |  Branch (1128:26): [True: 46, False: 23]
  ------------------
 1129|    100|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 20, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  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|     26|	} else { \
  |  |  |  |  159|     26|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     26|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     26|	} \
  |  |  |  |  162|     46|	return _ret; \
  |  |  |  |  163|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1130|       |
 1131|     54|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1132|     54|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     54|} 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|   498k|{
  112|   498k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  113|   498k|	int i;
  114|       |
  115|       |	/* Handle special cases here */
  116|   498k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (116:6): [True: 437, False: 498k]
  ------------------
  117|    437|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|    437|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  118|    437|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|    437|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  119|    437|	}
  120|   498k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (120:6): [True: 221k, False: 277k]
  |  Branch (120:21): [True: 215k, False: 5.37k]
  ------------------
  121|   215k|		return SC_SUCCESS;
  ------------------
  |  |   28|   215k|#define SC_SUCCESS				0
  ------------------
  122|   282k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (122:6): [True: 807, False: 281k]
  |  Branch (122:22): [True: 125, False: 682]
  ------------------
  123|    125|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  124|    125|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|    125|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  125|    125|	}
  126|  11.5M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (126:14): [True: 11.4M, False: 30.0k]
  ------------------
  127|  11.4M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (127:7): [True: 252k, False: 11.2M]
  ------------------
  128|   252k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   252k|#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|   252k|			return iso7816_errors[i].errorno;
  130|   252k|		}
  131|  11.4M|	}
  132|       |
  133|  30.0k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|  30.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  134|  30.0k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  30.0k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  135|   282k|}
iso7816.c:iso7816_process_fci:
  431|  9.69k|{
  432|  9.69k|	struct sc_context *ctx = card->ctx;
  433|  9.69k|	const unsigned char *p, *end;
  434|  9.69k|	unsigned int cla = 0, tag = 0;
  435|  9.69k|	size_t length;
  436|       |
  437|  9.69k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  9.69k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  438|       |
  439|  9.69k|	for (p = buf, length = buflen, end = buf + buflen;
  440|  28.2k|			p < end;
  ------------------
  |  Branch (440:4): [True: 24.8k, False: 3.42k]
  ------------------
  441|  24.8k|			p += length, length = end - p) {
  442|       |
  443|  24.8k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  24.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:7): [True: 4.31k, False: 20.5k]
  ------------------
  444|  20.5k|				|| p == NULL) {
  ------------------
  |  Branch (444:8): [True: 1.96k, False: 18.5k]
  ------------------
  445|  6.27k|			break;
  446|  6.27k|		}
  447|  18.5k|		switch (cla | tag) {
  ------------------
  |  Branch (447:11): [True: 14.1k, False: 4.43k]
  ------------------
  448|  1.91k|			case 0x81:
  ------------------
  |  Branch (448:4): [True: 1.91k, False: 16.6k]
  ------------------
  449|  1.91k|				if (file->size != 0) {
  ------------------
  |  Branch (449:9): [True: 95, False: 1.81k]
  ------------------
  450|       |					/* don't overwrite existing file size excluding structural information */
  451|     95|					break;
  452|     95|				}
  453|       |				/* fall through */
  454|  4.02k|			case 0x80:
  ------------------
  |  Branch (454:4): [True: 2.20k, False: 16.3k]
  ------------------
  455|       |				/* determine the file size */
  456|  4.02k|				file->size = 0;
  457|  4.02k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (457:9): [True: 4.02k, False: 0]
  |  Branch (457:14): [True: 3.98k, False: 41]
  ------------------
  458|  3.98k|					size_t size = 0, i;
  459|  13.0k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (459:18): [True: 9.07k, False: 3.98k]
  ------------------
  460|  9.07k|						size <<= 8;
  461|  9.07k|						size |= p[i];
  462|  9.07k|					}
  463|  3.98k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  3.98k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (463:10): [True: 532, False: 3.45k]
  ------------------
  464|    532|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  229|    532|#define MAX_FILE_SIZE 65535
  ------------------
  465|    532|						sc_log(ctx, "  file size truncated, encoded length: %"SC_FORMAT_LEN_SIZE_T"u", size);
  ------------------
  |  |   71|    532|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  466|  3.45k|					} else {
  467|  3.45k|						file->size = size;
  468|  3.45k|					}
  469|  3.98k|				}
  470|       |
  471|  4.02k|				sc_log(ctx, "  bytes in file: %"SC_FORMAT_LEN_SIZE_T"u", file->size);
  ------------------
  |  |   71|  4.02k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  472|  4.02k|				break;
  473|       |
  474|  2.05k|			case 0x82:
  ------------------
  |  Branch (474:4): [True: 2.05k, False: 16.5k]
  ------------------
  475|  2.05k|				if (length > 0) {
  ------------------
  |  Branch (475:9): [True: 1.81k, False: 239]
  ------------------
  476|  1.81k|					unsigned char byte = p[0];
  477|  1.81k|					const char *type;
  478|       |
  479|  1.81k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (479:24): [True: 346, False: 1.46k]
  ------------------
  480|  1.81k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 346, False: 1.46k]
  |  |  ------------------
  ------------------
  481|  1.81k|					file->ef_structure = byte & 0x07;
  482|  1.81k|					switch ((byte >> 3) & 7) {
  483|    984|						case 0:
  ------------------
  |  Branch (483:7): [True: 984, False: 830]
  ------------------
  484|    984|							type = "working EF";
  485|    984|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    984|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  486|    984|							break;
  487|    241|						case 1:
  ------------------
  |  Branch (487:7): [True: 241, False: 1.57k]
  ------------------
  488|    241|							type = "internal EF";
  489|    241|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    241|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  490|    241|							break;
  491|    246|						case 7:
  ------------------
  |  Branch (491:7): [True: 246, False: 1.56k]
  ------------------
  492|    246|							type = "DF";
  493|    246|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    246|#define SC_FILE_TYPE_DF			0x04
  ------------------
  494|    246|							break;
  495|    343|						default:
  ------------------
  |  Branch (495:7): [True: 343, False: 1.47k]
  ------------------
  496|    343|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    343|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  497|    343|							type = "unknown";
  498|    343|							break;
  499|  1.81k|					}
  500|  1.81k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  501|  1.81k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  502|  1.81k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  503|       |
  504|       |					/* if possible, get additional information for non-DFs */
  505|  1.81k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  1.81k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (505:10): [True: 1.56k, False: 246]
  ------------------
  506|       |						/* max. record length for fixed- & variable-sized records */
  507|  1.56k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (507:11): [True: 594, False: 974]
  |  Branch (507:25): [True: 452, False: 142]
  ------------------
  508|    452|							file->record_length = (length > 3)
  ------------------
  |  Branch (508:30): [True: 380, False: 72]
  ------------------
  509|    452|								? bebytes2ushort(p+2)
  510|    452|								: p[2];
  511|    452|							sc_log(ctx, "  record length: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  512|    452|								file->record_length);
  513|    452|						}
  514|       |
  515|       |						/* number of records */
  516|  1.56k|						if (length > 4) {
  ------------------
  |  Branch (516:11): [True: 302, False: 1.26k]
  ------------------
  517|    302|							file->record_count = (length > 5)
  ------------------
  |  Branch (517:29): [True: 88, False: 214]
  ------------------
  518|    302|								? bebytes2ushort(p+4)
  519|    302|								: p[4];
  520|    302|							sc_log(ctx, "  records: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  521|    302|								file->record_count);
  522|    302|						}
  523|  1.56k|					}
  524|       |
  525|  1.81k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  1.81k|#define SC_SUCCESS				0
  ------------------
  |  Branch (525:10): [True: 0, False: 1.81k]
  ------------------
  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.81k|				}
  528|  2.05k|				break;
  529|       |
  530|  2.05k|			case 0x83:
  ------------------
  |  Branch (530:4): [True: 1.22k, False: 17.3k]
  ------------------
  531|  1.22k|				if (length == 2) {
  ------------------
  |  Branch (531:9): [True: 916, False: 313]
  ------------------
  532|    916|					file->id = (p[0] << 8) | p[1];
  533|    916|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|    916|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  534|    916|				}
  535|  1.22k|				break;
  536|       |
  537|    514|			case 0x84:
  ------------------
  |  Branch (537:4): [True: 514, False: 18.0k]
  ------------------
  538|    514|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (538:9): [True: 434, False: 80]
  |  Branch (538:23): [True: 416, False: 18]
  ------------------
  539|    416|					memcpy(file->name, p, length);
  540|    416|					file->namelen = length;
  541|       |
  542|    416|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    416|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    416|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  543|    416|					if (!file->type)
  ------------------
  |  Branch (543:10): [True: 260, False: 156]
  ------------------
  544|    260|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    260|#define SC_FILE_TYPE_DF			0x04
  ------------------
  545|    416|				}
  546|    514|				break;
  547|       |
  548|  1.05k|			case 0x85:
  ------------------
  |  Branch (548:4): [True: 1.05k, False: 17.5k]
  ------------------
  549|  1.42k|			case 0xA5:
  ------------------
  |  Branch (549:4): [True: 366, False: 18.2k]
  ------------------
  550|  1.42k|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|  1.42k|#define SC_SUCCESS				0
  ------------------
  |  Branch (550:9): [True: 0, False: 1.42k]
  ------------------
  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.42k|				break;
  554|       |
  555|  1.30k|			case 0x86:
  ------------------
  |  Branch (555:4): [True: 1.30k, False: 17.2k]
  ------------------
  556|  1.30k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.30k|#define SC_SUCCESS				0
  ------------------
  |  Branch (556:9): [True: 0, False: 1.30k]
  ------------------
  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.30k|				break;
  560|       |
  561|    497|			case 0x88:
  ------------------
  |  Branch (561:4): [True: 497, False: 18.1k]
  ------------------
  562|    497|				if (length == 1) {
  ------------------
  |  Branch (562:9): [True: 90, False: 407]
  ------------------
  563|     90|					file->sid = *p;
  564|     90|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  565|     90|				}
  566|    497|				break;
  567|       |
  568|  1.48k|			case 0x8A:
  ------------------
  |  Branch (568:4): [True: 1.48k, False: 17.1k]
  ------------------
  569|  1.48k|				if (length == 1) {
  ------------------
  |  Branch (569:9): [True: 1.23k, False: 250]
  ------------------
  570|  1.23k|					switch (p[0]) {
  571|     66|						case 0:
  ------------------
  |  Branch (571:7): [True: 66, False: 1.16k]
  ------------------
  572|     66|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|     66|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  573|     66|							break;
  574|     69|						case 1:
  ------------------
  |  Branch (574:7): [True: 69, False: 1.16k]
  ------------------
  575|     69|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     69|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  576|     69|							break;
  577|     67|						case 3:
  ------------------
  |  Branch (577:7): [True: 67, False: 1.16k]
  ------------------
  578|     67|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|     67|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  579|     67|							break;
  580|     66|						case 4:
  ------------------
  |  Branch (580:7): [True: 66, False: 1.16k]
  ------------------
  581|    132|						case 6:
  ------------------
  |  Branch (581:7): [True: 66, False: 1.16k]
  ------------------
  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|    156|						case 5:
  ------------------
  |  Branch (584:7): [True: 156, False: 1.07k]
  ------------------
  585|    223|						case 7:
  ------------------
  |  Branch (585:7): [True: 67, False: 1.16k]
  ------------------
  586|    223|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    223|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  587|    223|							break;
  588|     66|						case 12:
  ------------------
  |  Branch (588:7): [True: 66, False: 1.16k]
  ------------------
  589|    132|						case 13:
  ------------------
  |  Branch (589:7): [True: 66, False: 1.16k]
  ------------------
  590|    201|						case 14:
  ------------------
  |  Branch (590:7): [True: 69, False: 1.16k]
  ------------------
  591|    267|						case 15:
  ------------------
  |  Branch (591:7): [True: 66, False: 1.16k]
  ------------------
  592|    267|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|    267|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  593|    267|							break;
  594|     66|						case 2:
  ------------------
  |  Branch (594:7): [True: 66, False: 1.16k]
  ------------------
  595|     66|							file->status = SC_FILE_STATUS_RFU_2;
  ------------------
  |  |  248|     66|#define SC_FILE_STATUS_RFU_2		0x07 /* ISO7816-4: (0x02) */
  ------------------
  596|     66|							break;
  597|     67|						case 8:
  ------------------
  |  Branch (597:7): [True: 67, False: 1.16k]
  ------------------
  598|     67|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|     67|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  599|     67|							break;
  600|     66|						case 9:
  ------------------
  |  Branch (600:7): [True: 66, False: 1.16k]
  ------------------
  601|     66|							file->status = SC_FILE_STATUS_RFU_9;
  ------------------
  |  |  250|     66|#define SC_FILE_STATUS_RFU_9		0x09 /* ISO7816-4: (0x09) */
  ------------------
  602|     66|							break;
  603|     66|						case 10:
  ------------------
  |  Branch (603:7): [True: 66, False: 1.16k]
  ------------------
  604|     66|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     66|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  605|     66|							break;
  606|     66|						case 11:
  ------------------
  |  Branch (606:7): [True: 66, False: 1.16k]
  ------------------
  607|     66|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     66|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  608|     66|							break;
  609|     79|						default:
  ------------------
  |  Branch (609:7): [True: 79, False: 1.15k]
  ------------------
  610|     79|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|     79|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  611|  1.23k|					}
  612|  1.23k|				}
  613|  1.48k|				break;
  614|       |
  615|  1.48k|			case 0x62:
  ------------------
  |  Branch (615:4): [True: 952, False: 17.6k]
  ------------------
  616|  1.06k|			case 0x64:
  ------------------
  |  Branch (616:4): [True: 115, False: 18.4k]
  ------------------
  617|  1.53k|			case 0x6F:
  ------------------
  |  Branch (617:4): [True: 468, False: 18.1k]
  ------------------
  618|       |				/* allow nested FCP/FMD/FCI templates */
  619|  1.53k|				iso7816_process_fci(card, file, p, length);
  620|  18.5k|		}
  621|  18.5k|	}
  622|       |
  623|  9.69k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  9.69k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  624|       |
  625|  9.69k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.69k|#define SC_SUCCESS				0
  ------------------
  626|  9.69k|}
iso7816.c:iso7816_pin_cmd:
 1288|  8.49k|{
 1289|  8.49k|	struct sc_apdu local_apdu, *apdu;
 1290|  8.49k|	int r;
 1291|  8.49k|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1292|       |
 1293|  8.49k|	data->pin1.tries_left = -1;
 1294|       |
 1295|       |	/* Many cards do support PIN status queries, but some cards don't and
 1296|       |	 * mistakenly count the command as a failed PIN attempt, so for now we
 1297|       |	 * allow cards with this flag.  In future this may be reduced to a
 1298|       |	 * blocklist, subject to testing more cards. */
 1299|  8.49k|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  425|  16.9k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1299:6): [True: 6.83k, False: 1.65k]
  ------------------
 1300|  6.83k|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  560|  6.83k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1300:6): [True: 142, False: 6.69k]
  ------------------
 1301|    142|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   71|    142|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1302|    142|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    142|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1303|    142|	}
 1304|       |
 1305|       |	/* See if we've been called from another card driver, which is
 1306|       |	 * passing an APDU to us (this allows to write card drivers
 1307|       |	 * whose PIN functions behave "mostly like ISO" except in some
 1308|       |	 * special circumstances.
 1309|       |	 */
 1310|  8.35k|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1310:6): [True: 8.34k, False: 7]
  ------------------
 1311|  8.34k|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1312|  8.34k|		if (r < 0)
  ------------------
  |  Branch (1312:7): [True: 68, False: 8.27k]
  ------------------
 1313|     68|			return r;
 1314|  8.27k|		data->apdu = &local_apdu;
 1315|  8.27k|	}
 1316|  8.28k|	apdu = data->apdu;
 1317|       |
 1318|  8.28k|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  428|  8.28k|#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 (1318:6): [True: 8.28k, False: 0]
  |  Branch (1318:48): [True: 0, False: 0]
  ------------------
 1319|       |		/* Transmit the APDU to the card */
 1320|  8.28k|		r = sc_transmit_apdu(card, apdu);
 1321|       |
 1322|       |		/* Clear the buffer - it may contain pins */
 1323|  8.28k|		sc_mem_clear(sbuf, sizeof(sbuf));
 1324|  8.28k|	}
 1325|      0|	else {
 1326|       |		/* Call the reader driver to collect
 1327|       |		 * the PIN and pass on the APDU to the card */
 1328|      0|		if (data->pin1.offset == 0) {
  ------------------
  |  Branch (1328:7): [True: 0, False: 0]
  ------------------
 1329|      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__
  |  |  ------------------
  ------------------
 1330|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1331|      0|		}
 1332|      0|		if (card->reader && card->reader->ops && card->reader->ops->perform_verify) {
  ------------------
  |  Branch (1332:7): [True: 0, False: 0]
  |  Branch (1332:23): [True: 0, False: 0]
  |  Branch (1332:44): [True: 0, False: 0]
  ------------------
 1333|      0|			r = card->reader->ops->perform_verify(card->reader, data);
 1334|       |			/* sw1/sw2 filled in by reader driver */
 1335|      0|		}
 1336|      0|		else {
 1337|      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__
  |  |  ------------------
  ------------------
 1338|      0|					"PIN entry through reader key pad");
 1339|      0|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1340|      0|		}
 1341|      0|	}
 1342|       |
 1343|       |	/* Don't pass references to local variables up to the caller. */
 1344|  8.28k|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1344:6): [True: 8.27k, False: 7]
  ------------------
 1345|  8.27k|		data->apdu = NULL;
 1346|       |
 1347|  8.28k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  8.28k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  8.28k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  8.28k|	int _ret = (r); \
  |  |  |  |  168|  8.28k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 46, False: 8.23k]
  |  |  |  |  ------------------
  |  |  |  |  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|  8.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1348|  8.23k|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1349|       |
 1350|  8.23k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  8.23k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1350:6): [True: 2.04k, False: 6.19k]
  ------------------
 1351|  2.04k|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|  2.04k|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1352|  6.19k|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|  6.19k|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1352:13): [True: 39, False: 6.15k]
  ------------------
 1353|     39|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1354|     39|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|     39|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1355|     39|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  425|     39|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1355:7): [True: 17, False: 22]
  ------------------
 1356|     17|			r = SC_SUCCESS;
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
 1357|  6.15k|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|  6.15k|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1357:13): [True: 7, False: 6.14k]
  ------------------
 1358|      7|		data->pin1.tries_left = 0;
 1359|      7|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|      7|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1360|      7|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  425|      7|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1360:7): [True: 4, False: 3]
  ------------------
 1361|      4|			r = SC_SUCCESS;
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
 1362|      7|	}
 1363|       |
 1364|  8.23k|	return r;
 1365|  8.28k|}
iso7816.c:iso7816_get_data:
 1369|    232|{
 1370|    232|	int                             r, cse;
 1371|    232|	struct sc_apdu                  apdu;
 1372|       |
 1373|    232|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    232|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    232|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    232|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 232]
  |  |  ------------------
  ------------------
 1374|       |
 1375|    232|	if (buf && len)
  ------------------
  |  Branch (1375:6): [True: 232, False: 0]
  |  Branch (1375:13): [True: 232, False: 0]
  ------------------
 1376|    232|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    232|#define SC_APDU_CASE_2			0x22
  ------------------
 1377|      0|	else
 1378|      0|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1379|       |
 1380|    232|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1381|    232|	apdu.le = len;
 1382|    232|	apdu.resp = buf;
 1383|    232|	apdu.resplen = len;
 1384|    232|	r = sc_transmit_apdu(card, &apdu);
 1385|    232|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    232|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    232|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    232|	int _ret = (r); \
  |  |  |  |  168|    232|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 223]
  |  |  |  |  ------------------
  |  |  |  |  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|    232|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 223]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1386|       |
 1387|    223|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1388|    223|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  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: 75, False: 148]
  |  |  |  |  ------------------
  |  |  |  |  169|     75|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     75|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     75|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     75|		return _ret; \
  |  |  |  |  172|     75|	} \
  |  |  |  |  173|    223|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 148]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1389|       |
 1390|    148|	if (apdu.resplen > len)
  ------------------
  |  Branch (1390:6): [True: 0, False: 148]
  ------------------
 1391|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1392|    148|	else
 1393|    148|		r = (int)apdu.resplen;
 1394|       |
 1395|    148|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    148|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    148|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    148|	int _ret = r; \
  |  |  |  |  155|    148|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 36, False: 112]
  |  |  |  |  ------------------
  |  |  |  |  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|    112|	} else { \
  |  |  |  |  159|    112|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    112|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    112|	} \
  |  |  |  |  162|    148|	return _ret; \
  |  |  |  |  163|    148|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1396|    148|}
iso7816.c:iso7816_read_binary:
  140|  34.5k|{
  141|  34.5k|	struct sc_context *ctx = card->ctx;
  142|  34.5k|	struct sc_apdu apdu;
  143|  34.5k|	int r;
  144|       |
  145|  34.5k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (145:6): [True: 2, False: 34.5k]
  ------------------
  146|      2|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  147|      2|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      2|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  148|      2|	}
  149|       |
  150|  34.5k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  34.5k|#define SC_APDU_CASE_2			0x22
  ------------------
  151|  34.5k|	apdu.le = count;
  152|  34.5k|	apdu.resplen = count;
  153|  34.5k|	apdu.resp = buf;
  154|       |
  155|  34.5k|	iso7816_fixup_transceive_length(card, &apdu);
  156|  34.5k|	r = sc_transmit_apdu(card, &apdu);
  157|  34.5k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  34.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  34.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  34.5k|	int _ret = (r); \
  |  |  |  |  168|  34.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 305, False: 34.2k]
  |  |  |  |  ------------------
  |  |  |  |  169|    305|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    305|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    305|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    305|		return _ret; \
  |  |  |  |  172|    305|	} \
  |  |  |  |  173|  34.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|       |
  159|  34.2k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  160|  34.2k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  68.4k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  33.0k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (160:6): [True: 1.22k, False: 33.0k]
  |  Branch (160:40): [True: 978, False: 32.0k]
  ------------------
  161|  34.2k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  2.20k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.20k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.20k|	int _ret = r; \
  |  |  |  |  155|  2.20k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 542, False: 1.65k]
  |  |  |  |  ------------------
  |  |  |  |  156|    542|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 542]
  |  |  |  |  ------------------
  |  |  |  |  157|    542|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.65k|	} 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|  2.20k|	return _ret; \
  |  |  |  |  163|  2.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|  32.0k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  32.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  32.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  32.0k|	int _ret = (r); \
  |  |  |  |  168|  32.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.87k, False: 29.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.87k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.87k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.87k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.87k|		return _ret; \
  |  |  |  |  172|  2.87k|	} \
  |  |  |  |  173|  32.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 29.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  163|       |
  164|  29.1k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  29.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  29.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  29.1k|	int _ret = r; \
  |  |  |  |  155|  29.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.36k, False: 27.7k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.36k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.36k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.36k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  27.7k|	} else { \
  |  |  |  |  159|  27.7k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  27.7k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  27.7k|	} \
  |  |  |  |  162|  29.1k|	return _ret; \
  |  |  |  |  163|  29.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|  29.1k|}

sc_do_log:
   58|  17.5M|{
   59|  17.5M|	va_list ap;
   60|       |
   61|  17.5M|	va_start(ap, format);
   62|  17.5M|	sc_do_log_va(ctx, level, file, line, func, 0, format, ap);
   63|       |	va_end(ap);
   64|  17.5M|}
sc_do_log_color:
   67|  5.17M|{
   68|  5.17M|	va_list ap;
   69|       |
   70|  5.17M|	va_start(ap, format);
   71|  5.17M|	sc_do_log_va(ctx, level, file, line, func, color, format, ap);
   72|       |	va_end(ap);
   73|  5.17M|}
sc_do_log_openssl:
   77|  5.76k|{
   78|  5.76k|	BIO *bio = NULL;
   79|  5.76k|	int length, rc;
   80|  5.76k|	char *buffer = NULL;
   81|       |
   82|  5.76k|	if ((bio = BIO_new(BIO_s_mem())) == NULL) {
  ------------------
  |  Branch (82:6): [True: 0, False: 5.76k]
  ------------------
   83|      0|		sc_do_log(ctx, level, file, line, func, "Cannot log OpenSSL error");
   84|      0|		goto end;
   85|      0|	}
   86|  5.76k|	ERR_print_errors(bio);
   87|       |
   88|  5.76k|	length = BIO_pending(bio);
   89|  5.76k|	if (length <= 0) {
  ------------------
  |  Branch (89:6): [True: 5.76k, False: 2]
  ------------------
   90|       |		/* no error? */
   91|  5.76k|		goto end;
   92|  5.76k|	}
   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|  5.76k|end:
  108|  5.76k|	free(buffer);
  109|  5.76k|	BIO_free(bio);
  110|  5.76k|}
_sc_debug_hex:
  343|   534k|{
  344|   534k|	size_t blen = len * 5 + 128;
  345|   534k|	char *buf = malloc(blen);
  346|   534k|	if (buf == NULL)
  ------------------
  |  Branch (346:6): [True: 0, False: 534k]
  ------------------
  347|      0|		return;
  348|       |
  349|   534k|	sc_hex_dump(data, len, buf, blen);
  350|       |
  351|   534k|	if (label)
  ------------------
  |  Branch (351:6): [True: 534k, False: 0]
  ------------------
  352|   534k|		sc_do_log(ctx, type, file, line, func,
  353|   534k|			"\n%s (%"SC_FORMAT_LEN_SIZE_T"u byte%s):\n%s",
  354|   534k|			label, len, len==1?"":"s", buf);
  ------------------
  |  Branch (354:16): [True: 1.71k, False: 532k]
  ------------------
  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|   534k|	free(buf);
  361|   534k|}
sc_hex_dump:
  364|   534k|{
  365|   534k|	char *p = buf;
  366|   534k|	size_t p_len = len;
  367|   534k|	int lines = 0;
  368|       |
  369|   534k|	if (buf == NULL || (in == NULL && count != 0)) {
  ------------------
  |  Branch (369:6): [True: 0, False: 534k]
  |  Branch (369:22): [True: 389, False: 534k]
  |  Branch (369:36): [True: 0, False: 389]
  ------------------
  370|      0|		return;
  371|      0|	}
  372|   534k|	buf[0] = 0;
  373|   534k|	if ((count * 5) > len)
  ------------------
  |  Branch (373:6): [True: 0, False: 534k]
  ------------------
  374|      0|		return;
  375|  3.09M|	while (count) {
  ------------------
  |  Branch (375:9): [True: 2.55M, False: 534k]
  ------------------
  376|  2.55M|		char ascbuf[17];
  377|  2.55M|		size_t i;
  378|       |
  379|  40.5M|		for (i = 0; i < count && i < 16; i++) {
  ------------------
  |  Branch (379:15): [True: 40.0M, False: 421k]
  |  Branch (379:28): [True: 37.9M, False: 2.13M]
  ------------------
  380|  37.9M|			sprintf(p, "%02X ", *in);
  381|  37.9M|			if (isprint(*in))
  ------------------
  |  Branch (381:8): [True: 19.4M, False: 18.4M]
  ------------------
  382|  19.4M|				ascbuf[i] = *in;
  383|  18.4M|			else
  384|  18.4M|				ascbuf[i] = '.';
  385|  37.9M|			p += 3;
  386|  37.9M|			p_len -= 3;
  387|  37.9M|			in++;
  388|  37.9M|		}
  389|  2.55M|		count -= i;
  390|  2.55M|		ascbuf[i] = 0;
  391|  3.11M|		for (; i < 16 && lines; i++) {
  ------------------
  |  Branch (391:10): [True: 773k, False: 2.34M]
  |  Branch (391:20): [True: 561k, False: 212k]
  ------------------
  392|   561k|			strlcat(p, "   ", p_len);
  393|   561k|			p += 3;
  394|   561k|			p_len -= 3;
  395|   561k|		}
  396|  2.55M|		snprintf(p, p_len, "%s\n", ascbuf);
  397|  2.55M|		p += strlen(ascbuf) + 1;
  398|  2.55M|		p_len -= strlen(ascbuf) - 1;
  399|  2.55M|		lines++;
  400|  2.55M|	}
  401|   534k|}
sc_dump_hex:
  405|   213k|{
  406|   213k|	static char dump_buf[0x1000];
  407|   213k|	size_t ii, size = sizeof(dump_buf) - 0x10;
  408|   213k|	size_t offs = 0;
  409|       |
  410|   213k|	memset(dump_buf, 0, sizeof(dump_buf));
  411|   213k|	if (in == NULL)
  ------------------
  |  Branch (411:6): [True: 0, False: 213k]
  ------------------
  412|      0|		return dump_buf;
  413|       |
  414|  1.21M|	for (ii=0; ii<count; ii++) {
  ------------------
  |  Branch (414:13): [True: 1.00M, False: 213k]
  ------------------
  415|  1.00M|		if (ii && !(ii%16))   {
  ------------------
  |  Branch (415:7): [True: 916k, False: 84.4k]
  |  Branch (415:13): [True: 19.0k, False: 897k]
  ------------------
  416|  19.0k|			if (!(ii%48))
  ------------------
  |  Branch (416:8): [True: 5.15k, False: 13.8k]
  ------------------
  417|  5.15k|				snprintf(dump_buf + offs, size - offs, "\n");
  418|  13.8k|			else
  419|  13.8k|				snprintf(dump_buf + offs, size - offs, " ");
  420|  19.0k|			offs = strlen(dump_buf);
  421|  19.0k|		}
  422|       |
  423|  1.00M|		snprintf(dump_buf + offs, size - offs, "%02X", *(in + ii));
  424|  1.00M|		offs += 2;
  425|       |
  426|  1.00M|		if (offs > size)
  ------------------
  |  Branch (426:7): [True: 0, False: 1.00M]
  ------------------
  427|      0|			break;
  428|  1.00M|	}
  429|       |
  430|   213k|	if (ii<count)
  ------------------
  |  Branch (430:6): [True: 0, False: 213k]
  ------------------
  431|      0|		snprintf(dump_buf + offs, sizeof(dump_buf) - offs, "....\n");
  432|       |
  433|   213k|	return dump_buf;
  434|   213k|}
sc_dump_oid:
  438|  6.06k|{
  439|  6.06k|	static char dump_buf[SC_MAX_OBJECT_ID_OCTETS * 20];
  440|  6.06k|        size_t ii;
  441|       |
  442|  6.06k|	memset(dump_buf, 0, sizeof(dump_buf));
  443|  6.06k|	if (oid)
  ------------------
  |  Branch (443:6): [True: 6.06k, False: 0]
  ------------------
  444|  46.0k|		for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS && oid->value[ii] != -1; ii++)
  ------------------
  |  |   46|  92.1k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (444:14): [True: 46.0k, False: 0]
  |  Branch (444:44): [True: 40.0k, False: 6.06k]
  ------------------
  445|  40.0k|			snprintf(dump_buf + strlen(dump_buf), sizeof(dump_buf) - strlen(dump_buf), "%s%i", (ii ? "." : ""), oid->value[ii]);
  ------------------
  |  Branch (445:88): [True: 33.9k, False: 6.06k]
  ------------------
  446|       |
  447|  6.06k|	return dump_buf;
  448|  6.06k|}
log.c:sc_do_log_va:
  124|  22.7M|{
  125|       |#ifdef _WIN32
  126|       |	SYSTEMTIME st;
  127|       |#else
  128|  22.7M|	struct tm *tm;
  129|  22.7M|	struct timeval tv;
  130|  22.7M|	char time_string[40];
  131|  22.7M|#endif
  132|       |
  133|  22.7M|	if (!ctx || ctx->debug < level)
  ------------------
  |  Branch (133:6): [True: 0, False: 22.7M]
  |  Branch (133:14): [True: 22.7M, False: 0]
  ------------------
  134|  22.7M|		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|    524|mscfs_t *mscfs_new(void) {
   46|    524|	mscfs_t *fs = malloc(sizeof(mscfs_t));
   47|    524|	if (!fs)
  ------------------
  |  Branch (47:6): [True: 0, False: 524]
  ------------------
   48|      0|		return NULL;
   49|    524|	memset(fs, 0, sizeof(mscfs_t));
   50|    524|	memcpy(fs->currentPath, "\x3F\x00", 2);
   51|    524|	return fs;
   52|    524|}
mscfs_free:
   54|    524|void mscfs_free(mscfs_t *fs) {
   55|    524|	mscfs_clear_cache(fs);
   56|    524|	free(fs);
   57|    524|}
mscfs_clear_cache:
   59|  1.83k|void mscfs_clear_cache(mscfs_t* fs) {
   60|  1.83k|	if(!fs->cache.array) {
  ------------------
  |  Branch (60:5): [True: 1.48k, False: 349]
  ------------------
   61|  1.48k|		return;
   62|  1.48k|	}
   63|    349|	free(fs->cache.array);
   64|       |	fs->cache.array = NULL;
   65|    349|	fs->cache.totalSize = 0;
   66|    349|	fs->cache.size = 0;
   67|    349|}
mscfs_push_file:
   83|  42.5k|{
   84|  42.5k|	mscfs_cache_t *cache = &fs->cache;
   85|  42.5k|	if (cache->size >= MAX_FILES)
  ------------------
  |  |   81|  42.5k|#define MAX_FILES 10000
  ------------------
  |  Branch (85:6): [True: 1, False: 42.5k]
  ------------------
   86|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
   87|  42.5k|	if(!cache->array || cache->size == cache->totalSize) {
  ------------------
  |  Branch (87:5): [True: 349, False: 42.2k]
  |  Branch (87:22): [True: 321, False: 41.9k]
  ------------------
   88|    670|		int length = cache->totalSize + MSCFS_CACHE_INCREMENT;
  ------------------
  |  |   35|    670|#define MSCFS_CACHE_INCREMENT 128
  ------------------
   89|    670|		mscfs_file_t *oldArray;
   90|    670|		cache->totalSize = length;
   91|    670|		oldArray = cache->array;
   92|    670|		cache->array = malloc(sizeof(mscfs_file_t) * length);
   93|    670|		if(!cache->array)
  ------------------
  |  Branch (93:6): [True: 0, False: 670]
  ------------------
   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|    670|		if(oldArray) {
  ------------------
  |  Branch (95:6): [True: 321, False: 349]
  ------------------
   96|    321|			memcpy(cache->array, oldArray, sizeof(mscfs_file_t) * cache->size);
   97|    321|			free(oldArray);
   98|    321|		}
   99|    670|	}
  100|  42.5k|	cache->array[cache->size] = *file;
  101|  42.5k|	cache->size++;
  102|  42.5k|	return SC_SUCCESS;
  ------------------
  |  |   28|  42.5k|#define SC_SUCCESS				0
  ------------------
  103|  42.5k|}
mscfs_update_cache:
  105|  1.31k|int mscfs_update_cache(mscfs_t* fs) {
  106|  1.31k|	mscfs_file_t file;
  107|  1.31k|	int r;
  108|  1.31k|	mscfs_clear_cache(fs);
  109|  1.31k|	r = fs->listFile(&file, 1, fs->udata);
  110|  1.31k|	if(r == 0)
  ------------------
  |  Branch (110:5): [True: 69, False: 1.24k]
  ------------------
  111|     69|		return 0;
  112|  1.24k|	else if(r < 0)
  ------------------
  |  Branch (112:10): [True: 862, False: 382]
  ------------------
  113|    862|		return r;
  114|  42.6k|	while(1) {
  ------------------
  |  Branch (114:8): [True: 42.6k, Folded]
  ------------------
  115|  42.6k|		if(!mscfs_is_ignored(fs, file.objectId)) {
  ------------------
  |  Branch (115:6): [True: 42.5k, False: 78]
  ------------------
  116|       |			/* Check if its a directory in the root */
  117|  42.5k|			u8* oid = file.objectId.id;
  118|  42.5k|			if(oid[2] == 0 && oid[3] == 0) {
  ------------------
  |  Branch (118:7): [True: 17.8k, False: 24.7k]
  |  Branch (118:22): [True: 9.09k, False: 8.72k]
  ------------------
  119|  9.09k|				oid[2] = oid[0];
  120|  9.09k|				oid[3] = oid[1];
  121|  9.09k|				oid[0] = 0x3F;
  122|  9.09k|				oid[1] = 0x00;
  123|  9.09k|				file.ef = 0;
  124|  33.5k|			} else  {
  125|  33.5k|				file.ef = 1; /* File is a working elementary file */
  126|  33.5k|			}
  127|       |
  128|  42.5k|			r = mscfs_push_file(fs, &file);
  129|  42.5k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  42.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (129:8): [True: 1, False: 42.5k]
  ------------------
  130|      1|				return r;
  131|  42.5k|		}
  132|  42.6k|		r = fs->listFile(&file, 0, fs->udata);
  133|  42.6k|		if(r == 0)
  ------------------
  |  Branch (133:6): [True: 124, False: 42.5k]
  ------------------
  134|    124|			break;
  135|  42.5k|		else if(r < 0)
  ------------------
  |  Branch (135:11): [True: 257, False: 42.2k]
  ------------------
  136|    257|			return r;
  137|  42.6k|	}
  138|    124|	return fs->cache.size;
  139|    382|}
mscfs_check_cache:
  142|  3.30k|{
  143|  3.30k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.30k|#define SC_SUCCESS				0
  ------------------
  144|  3.30k|	if(!fs->cache.array) {
  ------------------
  |  Branch (144:5): [True: 1.31k, False: 1.99k]
  ------------------
  145|  1.31k|		r = mscfs_update_cache(fs);
  146|  1.31k|	}
  147|  3.30k|	return r;
  148|  3.30k|}
mscfs_lookup_path:
  151|  1.40k|{
  152|  1.40k|	u8* oid = objectId->id;
  153|  1.40k|	if ((pathlen & 1) != 0) /* not divisible by 2 */
  ------------------
  |  Branch (153:6): [True: 587, False: 813]
  ------------------
  154|    587|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|    587|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|    587|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  155|    813|	if(isDirectory) {
  ------------------
  |  Branch (155:5): [True: 0, False: 813]
  ------------------
  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|    813|	oid[0] = fs->currentPath[0];
  167|    813|	oid[1] = fs->currentPath[1];
  168|       |	/* Chop off the root in the path */
  169|    813|	if(pathlen > 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (169:5): [True: 785, False: 28]
  |  Branch (169:20): [True: 762, False: 23]
  ------------------
  170|    762|		path += 2;
  171|    762|		pathlen -= 2;
  172|    762|		oid[0] = 0x3F;
  173|    762|		oid[1] = 0x00;
  174|    762|	}
  175|       |	/* Limit to a single directory */
  176|    813|	if(pathlen > 4)
  ------------------
  |  Branch (176:5): [True: 10, False: 803]
  ------------------
  177|     10|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|     10|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|     10|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  178|       |	/* Reset to root */
  179|    803|	if(pathlen == 2 && 0 == memcmp(path, "\x3F\x00", 2)) {
  ------------------
  |  Branch (179:5): [True: 475, False: 328]
  |  Branch (179:21): [True: 1, False: 474]
  ------------------
  180|      1|		oid[0] = oid[2] = path[0];
  181|      1|		oid[1] = oid[3] = path[1];
  182|    802|	} else if(pathlen == 2) { /* Path preserved for current-path */
  ------------------
  |  Branch (182:12): [True: 474, False: 328]
  ------------------
  183|    474|		oid[2] = path[0];
  184|    474|		oid[3] = path[1];
  185|    474|	} else if(pathlen == 4) {
  ------------------
  |  Branch (185:12): [True: 328, False: 0]
  ------------------
  186|    328|		oid[0] = path[0];
  187|    328|		oid[1] = path[1];
  188|    328|		oid[2] = path[2];
  189|    328|		oid[3] = path[3];
  190|    328|	}
  191|       |
  192|    803|	return 0;
  193|    813|}
mscfs_check_selection:
  207|    459|{
  208|    459|	if(fs->currentPath[0] == 0 && fs->currentPath[1] == 0)
  ------------------
  |  Branch (208:5): [True: 0, False: 459]
  |  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|    459|	if(requiredItem == 1 && fs->currentFile[0] == 0 && fs->currentFile[1] == 0)
  ------------------
  |  Branch (210:5): [True: 0, False: 459]
  |  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|    459|	return 0;
  213|    459|}
mscfs_loadFileInfo:
  216|  1.40k|{
  217|  1.40k|	msc_id fullPath = {{0, 0, 0, 0}};
  218|  1.40k|	int x, rc;
  219|  1.40k|	if (fs == NULL || path == NULL || file_data == NULL)
  ------------------
  |  Branch (219:6): [True: 0, False: 1.40k]
  |  Branch (219:20): [True: 0, False: 1.40k]
  |  Branch (219:36): [True: 0, False: 1.40k]
  ------------------
  220|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  221|  1.40k|	rc = mscfs_lookup_path(fs, path, pathlen, &fullPath, 0);
  222|  1.40k|	if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|  1.40k|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:6): [True: 597, False: 803]
  ------------------
  223|    597|		return rc;
  224|    597|	}
  225|       |
  226|       |	/* Obtain file information while checking if it exists */
  227|    803|	rc = mscfs_check_cache(fs);
  228|    803|	if (rc < 0)
  ------------------
  |  Branch (228:6): [True: 20, False: 783]
  ------------------
  229|     20|		return rc;
  230|    783|	if(idx) *idx = -1;
  ------------------
  |  Branch (230:5): [True: 783, False: 0]
  ------------------
  231|  85.2k|	for(x = 0; x < fs->cache.size; x++) {
  ------------------
  |  Branch (231:13): [True: 84.7k, False: 467]
  ------------------
  232|  84.7k|		*file_data = &fs->cache.array[x];
  233|  84.7k|		if (*file_data) {
  ------------------
  |  Branch (233:7): [True: 84.7k, False: 0]
  ------------------
  234|  84.7k|			msc_id objectId;
  235|  84.7k|			objectId = (*file_data)->objectId;
  236|  84.7k|			if(0 == memcmp(objectId.id, fullPath.id, 4)) {
  ------------------
  |  Branch (236:7): [True: 316, False: 84.4k]
  ------------------
  237|    316|				if (idx)
  ------------------
  |  Branch (237:9): [True: 316, False: 0]
  ------------------
  238|    316|					*idx = x;
  239|    316|				break;
  240|    316|			}
  241|  84.4k|			*file_data = NULL;
  242|  84.4k|		}
  243|  84.7k|	}
  244|    783|	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: 467, False: 316]
  |  Branch (244:28): [True: 1, False: 466]
  |  Branch (244:79): [True: 276, False: 190]
  |  Branch (244:131): [True: 1, False: 189]
  ------------------
  245|    278|		static mscfs_file_t ROOT_FILE;
  246|    278|		ROOT_FILE.ef = 0;
  247|    278|		ROOT_FILE.size = 0;
  248|       |		/* Faked Root ID */
  249|    278|		ROOT_FILE.objectId = rootId;
  250|       |
  251|    278|		ROOT_FILE.read = 0;
  252|    278|		ROOT_FILE.write = 0x02; /* User Pin access */
  253|    278|		ROOT_FILE.delete = 0x02;
  254|       |
  255|    278|		*file_data = &ROOT_FILE;
  256|    278|		if(idx) *idx = -2;
  ------------------
  |  Branch (256:6): [True: 278, False: 0]
  ------------------
  257|    505|	} else if(*file_data == NULL) {
  ------------------
  |  Branch (257:12): [True: 189, False: 316]
  ------------------
  258|    189|		return MSCFS_FILE_NOT_FOUND;
  ------------------
  |  |   34|    189|#define MSCFS_FILE_NOT_FOUND 	SC_ERROR_FILE_NOT_FOUND
  |  |  ------------------
  |  |  |  |   51|    189|#define SC_ERROR_FILE_NOT_FOUND			-1201
  |  |  ------------------
  ------------------
  259|    189|	}
  260|       |
  261|    594|	return 0;
  262|    783|}
muscle-filesystem.c:mscfs_is_ignored:
   70|  42.6k|{
   71|  42.6k|	int ignored = 0;
   72|  42.6k|	const u8** ptr = ignoredFiles;
   73|   127k|	while(ptr && *ptr && !ignored) {
  ------------------
  |  Branch (73:8): [True: 127k, False: 0]
  |  Branch (73:15): [True: 85.3k, False: 42.6k]
  |  Branch (73:23): [True: 85.2k, False: 60]
  ------------------
   74|  85.2k|		if(0 == memcmp(objectId.id, *ptr, 4))
  ------------------
  |  Branch (74:6): [True: 78, False: 85.2k]
  ------------------
   75|     78|			ignored = 1;
   76|  85.2k|		ptr++;
   77|  85.2k|	}
   78|  42.6k|	return ignored;
   79|  42.6k|}

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

sc_pkcs1_strip_02_padding_constant_time:
  154|    194|{
  155|    194|	unsigned int i = 0;
  156|    194|	u8 *msg, *msg_orig = NULL;
  157|    194|	unsigned int good, found_zero_byte, mask, tmp_outlen;
  158|    194|	unsigned int zero_index = 0, msg_index, mlen = -1, len = 0;
  159|    194|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    194|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    194|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    194|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    194|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 194]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|       |
  161|    194|	if (data == NULL || data_len <= 0 || data_len > n ||
  ------------------
  |  Branch (161:6): [True: 0, False: 194]
  |  Branch (161:22): [True: 48, False: 146]
  |  Branch (161:39): [True: 37, False: 109]
  ------------------
  162|    109|			n < SC_PKCS1_PADDING_MIN_SIZE || out_len == NULL)
  ------------------
  |  |   40|    303|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (162:4): [True: 0, False: 109]
  |  Branch (162:37): [True: 0, False: 109]
  ------------------
  163|    194|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|     85|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     85|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     85|	int _ret = r; \
  |  |  |  |  155|     85|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 85, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     85|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     85|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 85, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     85|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     85|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     85|	return _ret; \
  |  |  |  |  163|     85|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|       |
  165|    109|	tmp_outlen = *out_len;
  166|    109|	msg = msg_orig = calloc(n, sizeof(u8));
  167|    109|	if (msg == NULL)
  ------------------
  |  Branch (167:6): [True: 0, False: 109]
  ------------------
  168|    109|		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|    109|	len = data_len;
  177|  26.0k|	for (data += len, msg += n, i = 0; i < n; i++) {
  ------------------
  |  Branch (177:37): [True: 25.9k, False: 109]
  ------------------
  178|  25.9k|		mask = ~constant_time_is_zero(len);
  179|  25.9k|		len -= 1 & mask;
  180|  25.9k|		data -= 1 & mask;
  181|  25.9k|		*--msg = *data & mask;
  182|  25.9k|	}
  183|       |	// check first byte to be 0x00
  184|    109|	good = constant_time_is_zero(msg[0]);
  185|       |	// check second byte to be 0x02
  186|    109|	good &= constant_time_eq(msg[1], 2);
  187|       |
  188|       |	// find zero byte after random data in padding
  189|    109|	found_zero_byte = 0;
  190|  25.8k|	for (i = 2; i < n; i++) {
  ------------------
  |  Branch (190:14): [True: 25.7k, False: 109]
  ------------------
  191|  25.7k|		unsigned int equals0 = constant_time_is_zero(msg[i]);
  192|  25.7k|		zero_index = constant_time_select(~found_zero_byte & equals0, i, zero_index);
  193|  25.7k|		found_zero_byte |= equals0;
  194|  25.7k|	}
  195|       |
  196|       |	// zero_index stands for index of last found zero
  197|    109|	good &= constant_time_ge(zero_index, 2 + 8);
  198|       |
  199|       |	// start of the actual message in data
  200|    109|	msg_index = zero_index + 1;
  201|       |
  202|       |	// length of message
  203|    109|	mlen = data_len - msg_index;
  204|       |
  205|       |	// check that message fits into out buffer
  206|    109|	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|    109|	tmp_outlen = constant_time_select(constant_time_lt(n - SC_PKCS1_PADDING_MIN_SIZE, tmp_outlen),
  ------------------
  |  |   40|    109|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  210|    109|			n - SC_PKCS1_PADDING_MIN_SIZE, tmp_outlen);
  ------------------
  |  |   40|    109|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  211|    966|	for (msg_index = 1; msg_index < n - SC_PKCS1_PADDING_MIN_SIZE; msg_index <<= 1) {
  ------------------
  |  |   40|    966|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (211:22): [True: 857, False: 109]
  ------------------
  212|    857|		mask = ~constant_time_eq(msg_index & (n - SC_PKCS1_PADDING_MIN_SIZE - mlen), 0);
  ------------------
  |  |   40|    857|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  213|   174k|		for (i = SC_PKCS1_PADDING_MIN_SIZE; i < n - msg_index; i++)
  ------------------
  |  |   40|    857|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (213:39): [True: 173k, False: 857]
  ------------------
  214|   173k|			msg[i] = constant_time_select_8(mask, msg[i + msg_index], msg[i]);
  215|    857|	}
  216|       |	// move message into out buffer, if good
  217|  5.33k|	for (i = 0; i < tmp_outlen; i++) {
  ------------------
  |  Branch (217:14): [True: 5.22k, False: 109]
  ------------------
  218|  5.22k|		unsigned int msg_index;
  219|       |		// when out is longer than message in data, use some bogus index in msg
  220|  5.22k|		mask = good & constant_time_lt(i, mlen);
  221|  5.22k|		msg_index = constant_time_select(mask, i + SC_PKCS1_PADDING_MIN_SIZE, 0); // to now overflow msg buffer
  ------------------
  |  |   40|  5.22k|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  222|  5.22k|		out[i] = constant_time_select_8(mask, msg[msg_index], out[i]);
  223|  5.22k|	}
  224|       |
  225|    109|	*out_len = constant_time_select(good, mlen, *out_len);
  226|    109|	free(msg_orig);
  227|    109|	return constant_time_select(good, mlen, SC_ERROR_WRONG_PADDING);
  ------------------
  |  |   93|    109|#define SC_ERROR_WRONG_PADDING			-1412
  ------------------
  228|    109|}
sc_pkcs1_strip_digest_info_prefix:
  406|    180|{
  407|    180|	int i;
  408|       |
  409|  1.22k|	for (i = 0; digest_info_prefix[i].algorithm != 0; i++) {
  ------------------
  |  Branch (409:14): [True: 1.15k, False: 67]
  ------------------
  410|  1.15k|		size_t    hdr_len  = digest_info_prefix[i].hdr_len,
  411|  1.15k|		          hash_len = digest_info_prefix[i].hash_len;
  412|  1.15k|		const u8 *hdr      = digest_info_prefix[i].hdr;
  413|       |
  414|  1.15k|		if (in_len == (hdr_len + hash_len) &&
  ------------------
  |  Branch (414:7): [True: 157, False: 996]
  ------------------
  415|    157|		    !memcmp(in_dat, hdr, hdr_len)) {
  ------------------
  |  Branch (415:7): [True: 113, False: 44]
  ------------------
  416|    113|			if (algorithm)
  ------------------
  |  Branch (416:8): [True: 0, False: 113]
  ------------------
  417|      0|				*algorithm = digest_info_prefix[i].algorithm;
  418|    113|			if (out_dat == NULL)
  ------------------
  |  Branch (418:8): [True: 0, False: 113]
  ------------------
  419|       |				/* just check the DigestInfo prefix */
  420|      0|				return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  421|    113|			if (*out_len < hash_len)
  ------------------
  |  Branch (421:8): [True: 0, False: 113]
  ------------------
  422|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  423|    113|			memmove(out_dat, in_dat + hdr_len, hash_len);
  424|    113|			*out_len = hash_len;
  425|    113|			return SC_SUCCESS;
  ------------------
  |  |   28|    113|#define SC_SUCCESS				0
  ------------------
  426|    113|		}
  427|  1.15k|	}
  428|     67|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     67|#define SC_ERROR_INTERNAL			-1400
  ------------------
  429|    180|}
sc_pkcs1_encode:
  612|  6.49k|{
  613|  6.49k|	int    rv, i;
  614|  6.49k|	size_t tmp_len = *out_len;
  615|  6.49k|	const u8    *tmp = in;
  616|  6.49k|	unsigned int hash_algo, pad_algo;
  617|  6.49k|	size_t mod_len = BYTES4BITS(mod_bits);
  ------------------
  |  |  146|  6.49k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  618|  6.49k|#ifdef ENABLE_OPENSSL
  619|  6.49k|	size_t sLen;
  620|  6.49k|	EVP_MD* md = NULL;
  621|  6.49k|	unsigned int mgf1_hash;
  622|  6.49k|#endif
  623|       |
  624|  6.49k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  6.49k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.49k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.49k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.49k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.49k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  625|       |
  626|  6.49k|	hash_algo = flags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  151|  6.49k|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  627|  6.49k|	pad_algo  = flags & SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  112|  6.49k|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  628|  6.49k|	if (pad_algo == 0)
  ------------------
  |  Branch (628:6): [True: 34, False: 6.46k]
  ------------------
  629|     34|		pad_algo = SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  113|     34|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  630|  6.49k|	sc_log(ctx, "hash algorithm 0x%X, pad algorithm 0x%X", hash_algo, pad_algo);
  ------------------
  |  |   71|  6.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__
  |  |  ------------------
  ------------------
  631|       |
  632|  6.49k|	if ((pad_algo == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 || pad_algo == SC_ALGORITHM_RSA_PAD_NONE) &&
  ------------------
  |  |  118|  12.9k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              	if ((pad_algo == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 || pad_algo == SC_ALGORITHM_RSA_PAD_NONE) &&
  ------------------
  |  |  113|  5.79k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (632:7): [True: 700, False: 5.79k]
  |  Branch (632:57): [True: 34, False: 5.76k]
  ------------------
  633|    734|	    hash_algo != SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  142|    734|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (633:6): [True: 700, False: 34]
  ------------------
  634|    700|		i = sc_pkcs1_add_digest_info_prefix(hash_algo, in, in_len, out, &tmp_len);
  635|    700|		if (i != SC_SUCCESS) {
  ------------------
  |  |   28|    700|#define SC_SUCCESS				0
  ------------------
  |  Branch (635:7): [True: 700, False: 0]
  ------------------
  636|    700|			sc_log(ctx, "Unable to add digest info 0x%x", hash_algo);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  637|    700|			LOG_FUNC_RETURN(ctx, i);
  ------------------
  |  |  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: 700, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    700|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    700|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 700, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    700|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    700|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    700|	return _ret; \
  |  |  |  |  163|    700|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|    700|		}
  639|      0|		tmp = out;
  640|  5.79k|	} else   {
  641|  5.79k|		tmp_len = in_len;
  642|  5.79k|	}
  643|       |
  644|  5.79k|	switch(pad_algo) {
  645|     34|	case SC_ALGORITHM_RSA_PAD_NONE:
  ------------------
  |  |  113|     34|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (645:2): [True: 34, False: 5.76k]
  ------------------
  646|       |		/* padding done by card => nothing to do */
  647|     34|		if (out != tmp)
  ------------------
  |  Branch (647:7): [True: 34, False: 0]
  ------------------
  648|     34|			memcpy(out, tmp, tmp_len);
  649|     34|		*out_len = tmp_len;
  650|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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: 5.79k]
  ------------------
  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|  5.76k|	case SC_ALGORITHM_RSA_PAD_PSS:
  ------------------
  |  |  116|  5.76k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (655:2): [True: 5.76k, False: 34]
  ------------------
  656|       |		/* add PSS padding */
  657|  5.76k|#ifdef ENABLE_OPENSSL
  658|  5.76k|		mgf1_hash = flags & SC_ALGORITHM_MGF1_HASHES;
  ------------------
  |  |  159|  5.76k|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
  659|  5.76k|		if (hash_algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  142|  5.76k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (659:7): [True: 0, False: 5.76k]
  ------------------
  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|  5.76k|		if (!(md = hash_flag2md(ctx, hash_algo))) {
  ------------------
  |  Branch (669:7): [True: 5.76k, False: 0]
  ------------------
  670|  5.76k|			sc_log_openssl(ctx);
  ------------------
  |  |   72|  5.76k|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  671|  5.76k|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  5.76k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  672|  5.76k|		}
  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: 5.79k]
  ------------------
  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|  5.79k|	}
  695|  5.79k|}
sc_get_encoding_flags:
  700|  58.9k|{
  701|  58.9k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  58.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  58.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  58.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  58.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 58.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  702|  58.9k|	if (pflags == NULL || sflags == NULL)
  ------------------
  |  Branch (702:6): [True: 0, False: 58.9k]
  |  Branch (702:24): [True: 0, False: 58.9k]
  ------------------
  703|  58.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|  58.9k|	sc_log(ctx, "iFlags 0x%lX, card capabilities 0x%lX", iflags, caps);
  ------------------
  |  |   71|  58.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|  58.9k|	if ((caps & iflags) == iflags) {
  ------------------
  |  Branch (716:6): [True: 11.6k, False: 47.3k]
  ------------------
  717|       |		/* Card supports the signature operation we want to do, great, let's
  718|       |		 * go with it then. */
  719|  11.6k|		*sflags = iflags;
  720|  11.6k|		*pflags = 0;
  721|       |
  722|  47.3k|	} else if ((caps & SC_ALGORITHM_RSA_PAD_PSS) &&
  ------------------
  |  |  116|  47.3k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (722:13): [True: 4.45k, False: 42.8k]
  ------------------
  723|  4.45k|			(iflags & SC_ALGORITHM_RSA_PAD_PSS)) {
  ------------------
  |  |  116|  4.45k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (723:4): [True: 1.30k, False: 3.14k]
  ------------------
  724|  1.30k|		*sflags |= SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  116|  1.30k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  725|  1.30k|		*sflags |= iflags & SC_ALGORITHM_MGF1_HASHES;
  ------------------
  |  |  159|  1.30k|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
  726|  1.30k|		*pflags = iflags & ~(iflags & (SC_ALGORITHM_MGF1_HASHES | SC_ALGORITHM_RSA_PAD_PSS));
  ------------------
  |  |  159|  1.30k|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
              		*pflags = iflags & ~(iflags & (SC_ALGORITHM_MGF1_HASHES | SC_ALGORITHM_RSA_PAD_PSS));
  ------------------
  |  |  116|  1.30k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  727|       |
  728|  46.0k|	} else if ((caps & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  111|  46.0k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (728:13): [True: 24.3k, False: 21.6k]
  ------------------
  729|  24.3k|				(iflags & SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  120|  48.7k|#define SC_ALGORITHM_RSA_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|  24.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|  24.3k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (729:6): [True: 2.07k, False: 22.2k]
  ------------------
  730|  22.2k|				|| iflags & SC_ALGORITHM_RSA_PAD_PSS
  ------------------
  |  |  116|  46.6k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (730:8): [True: 5.76k, False: 16.5k]
  ------------------
  731|  16.5k|#ifdef ENABLE_OPENSSL
  732|  16.5k|				|| iflags & SC_ALGORITHM_RSA_PAD_OAEP
  ------------------
  |  |  117|  40.8k|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (732:8): [True: 0, False: 16.5k]
  ------------------
  733|  16.5k|#endif
  734|  16.5k|				|| iflags & SC_ALGORITHM_RSA_PAD_NONE)) {
  ------------------
  |  |  113|  16.5k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (734:8): [True: 0, False: 16.5k]
  ------------------
  735|       |		/* Use the card's raw RSA capability on the padded input */
  736|  7.84k|		*sflags = SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  113|  7.84k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  737|  7.84k|		*pflags = iflags;
  738|       |
  739|  38.1k|	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  118|  38.1k|#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|  38.1k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (739:13): [True: 29.0k, False: 9.12k]
  ------------------
  740|  29.0k|			(iflags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)) {
  ------------------
  |  |  118|  29.0k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (740:4): [True: 305, False: 28.7k]
  ------------------
  741|       |		/* A corner case - the card can partially do PKCS1, if we prepend the
  742|       |		 * DigestInfo bit it will do the rest. */
  743|    305|		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  118|    305|#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|    305|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  744|    305|		*pflags = iflags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  151|    305|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  745|       |
  746|  37.8k|	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  119|  37.8k|#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|  37.8k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (746:13): [True: 28.7k, False: 9.12k]
  ------------------
  747|  28.7k|			(iflags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)) {
  ------------------
  |  |  119|  28.7k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (747:4): [True: 0, False: 28.7k]
  ------------------
  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|  37.8k|	} 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|  37.8k|#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|  37.8k|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (751:13): [True: 0, False: 37.8k]
  ------------------
  752|      0|		*sflags = 0;
  753|      0|		*pflags = 0;
  754|       |
  755|  37.8k|	} else if ((iflags & SC_ALGORITHM_AES_FLAGS) > 0) {
  ------------------
  |  |  218|  37.8k|#define SC_ALGORITHM_AES_FLAGS		 0x0F000000
  ------------------
  |  Branch (755:13): [True: 1.26k, False: 36.5k]
  ------------------
  756|  1.26k|		*sflags = iflags & SC_ALGORITHM_AES_FLAGS;
  ------------------
  |  |  218|  1.26k|#define SC_ALGORITHM_AES_FLAGS		 0x0F000000
  ------------------
  757|  1.26k|		if (iflags & SC_ALGORITHM_AES_CBC_PAD)
  ------------------
  |  |  217|  1.26k|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  |  Branch (757:7): [True: 0, False: 1.26k]
  ------------------
  758|      0|			*pflags = SC_ALGORITHM_AES_CBC_PAD;
  ------------------
  |  |  217|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  759|  1.26k|		else
  760|  1.26k|			*pflags = 0;
  761|       |
  762|  36.5k|	} else {
  763|  36.5k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported algorithm");
  ------------------
  |  |  174|  36.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  36.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  36.5k|	int _ret = (r); \
  |  |  |  |  168|  36.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 36.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  36.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  36.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  36.5k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  36.5k|		return _ret; \
  |  |  |  |  172|  36.5k|	} \
  |  |  |  |  173|  36.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  764|  36.5k|	}
  765|       |
  766|  22.3k|	sc_log(ctx, "pad flags 0x%lX, secure algorithm flags 0x%lX", *pflags, *sflags);
  ------------------
  |  |   71|  22.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__
  |  |  ------------------
  ------------------
  767|  22.3k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  22.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  22.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  22.3k|	int _ret = r; \
  |  |  |  |  155|  22.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  22.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: 22.3k]
  |  |  |  |  ------------------
  |  |  |  |  157|  22.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  22.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|  22.3k|	return _ret; \
  |  |  |  |  163|  22.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  768|  22.3k|}
padding.c:hash_flag2md:
  434|  5.76k|{
  435|  5.76k|	switch (hash & SC_ALGORITHM_RSA_HASHES) {
  ------------------
  |  |  151|  5.76k|#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: 5.76k]
  ------------------
  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: 5.76k]
  ------------------
  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: 5.76k]
  ------------------
  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: 5.76k]
  ------------------
  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: 5.76k]
  ------------------
  445|      0|		return sc_evp_md(ctx, "SHA512");
  446|  5.76k|	default:
  ------------------
  |  Branch (446:2): [True: 5.76k, False: 0]
  ------------------
  447|       |		return NULL;
  448|  5.76k|	}
  449|  5.76k|}
padding.c:sc_pkcs1_add_digest_info_prefix:
  381|    700|{
  382|    700|	int i;
  383|       |
  384|  7.00k|	for (i = 0; digest_info_prefix[i].algorithm != 0; i++) {
  ------------------
  |  Branch (384:14): [True: 6.30k, False: 700]
  ------------------
  385|  6.30k|		if (algorithm == digest_info_prefix[i].algorithm) {
  ------------------
  |  Branch (385:7): [True: 0, False: 6.30k]
  ------------------
  386|      0|			const u8 *hdr      = digest_info_prefix[i].hdr;
  387|      0|			size_t    hdr_len  = digest_info_prefix[i].hdr_len,
  388|      0|			          hash_len = digest_info_prefix[i].hash_len;
  389|       |
  390|      0|			if (in_len != hash_len || *out_len < (hdr_len + hash_len))
  ------------------
  |  Branch (390:8): [True: 0, False: 0]
  |  Branch (390:30): [True: 0, False: 0]
  ------------------
  391|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  392|       |
  393|      0|			memmove(out + hdr_len, in, hash_len);
  394|      0|			memmove(out, hdr, hdr_len);
  395|      0|			*out_len = hdr_len + hash_len;
  396|       |
  397|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  398|      0|		}
  399|  6.30k|	}
  400|       |
  401|    700|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    700|#define SC_ERROR_INTERNAL			-1400
  ------------------
  402|    700|}

sc_asn1_decode_algorithm_id:
  510|  4.53k|{
  511|  4.53k|	struct sc_asn1_pkcs15_algorithm_info *alg_info = NULL;
  512|  4.53k|	struct sc_asn1_entry asn1_alg_id[3];
  513|  4.53k|	int r;
  514|       |
  515|  4.53k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.53k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.53k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.53k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.53k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|  4.53k|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  517|  4.53k|	sc_format_asn1_entry(asn1_alg_id + 0, &id->oid, NULL, 0);
  518|       |
  519|  4.53k|	memset(id, 0, sizeof(*id));
  520|  4.53k|	r = _sc_asn1_decode(ctx, asn1_alg_id, in, len, &in, &len, 0, depth + 1);
  521|  4.53k|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of algo ID failed");
  ------------------
  |  |  174|  4.53k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.53k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.53k|	int _ret = (r); \
  |  |  |  |  168|  4.53k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 94, False: 4.43k]
  |  |  |  |  ------------------
  |  |  |  |  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|  4.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.43k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  522|       |
  523|  4.43k|        sc_log(ctx, "decoded OID '%s'", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   71|  4.43k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  524|       |
  525|       |	/* See if we understand the algorithm, and if we do, check
  526|       |	 * whether we know how to decode any additional parameters */
  527|  4.43k|	id->algorithm = (unsigned int ) -1;
  528|  4.43k|	alg_info = sc_asn1_get_algorithm_info(id);
  529|  4.43k|	if (alg_info != NULL) {
  ------------------
  |  Branch (529:6): [True: 2.30k, False: 2.13k]
  ------------------
  530|  2.30k|		id->algorithm = alg_info->id;
  531|  2.30k|		if (alg_info->decode) {
  ------------------
  |  Branch (531:7): [True: 1.10k, False: 1.20k]
  ------------------
  532|  1.10k|			if (asn1_alg_id[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|  1.10k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (532:8): [True: 11, False: 1.09k]
  ------------------
  533|     11|				sc_log(ctx, "SC_ASN1_PRESENT was set, so invalid");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  534|     11|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|     11|			}
  536|  1.09k|			r = alg_info->decode(ctx, &id->params, in, len, depth);
  537|  1.09k|		}
  538|  2.30k|	}
  539|       |
  540|  4.42k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  4.42k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.42k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.42k|	int _ret = r; \
  |  |  |  |  155|  4.42k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.42k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 39, False: 4.38k]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.42k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.42k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.42k|	return _ret; \
  |  |  |  |  163|  4.42k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  541|  4.42k|}
sc_asn1_encode_algorithm_id:
  547|  1.63k|{
  548|  1.63k|	struct sc_asn1_pkcs15_algorithm_info *alg_info;
  549|  1.63k|	struct sc_algorithm_id temp_id;
  550|  1.63k|	struct sc_asn1_entry asn1_alg_id[3];
  551|  1.63k|	u8 *obj = NULL;
  552|  1.63k|	size_t obj_len = 0;
  553|  1.63k|	int r;
  554|  1.63k|	u8 *tmp;
  555|       |
  556|  1.63k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.63k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.63k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  557|  1.63k|        sc_log(ctx, "type of algorithm to encode: %lu", id->algorithm);
  ------------------
  |  |   71|  1.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  558|  1.63k|	alg_info = sc_asn1_get_algorithm_info(id);
  559|  1.63k|	if (alg_info == NULL) {
  ------------------
  |  Branch (559:6): [True: 0, False: 1.63k]
  ------------------
  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.63k|	if (!sc_valid_oid(&id->oid)) {
  ------------------
  |  Branch (565:6): [True: 0, False: 1.63k]
  ------------------
  566|      0|		temp_id = *id;
  567|      0|		temp_id.oid = alg_info->oid;
  568|      0|		id = &temp_id;
  569|      0|	}
  570|       |
  571|  1.63k|        sc_log(ctx, "encode algo %s", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   71|  1.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  572|  1.63k|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  573|  1.63k|	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.63k|	if (id->algorithm != SC_ALGORITHM_EDDSA &&
  ------------------
  |  |   81|  3.26k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (579:6): [True: 1.63k, False: 0]
  ------------------
  580|  1.63k|	    id->algorithm != SC_ALGORITHM_XEDDSA &&
  ------------------
  |  |   82|  3.26k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (580:6): [True: 1.63k, False: 0]
  ------------------
  581|  1.63k|	    (!id->params || !alg_info->encode))
  ------------------
  |  Branch (581:7): [True: 752, False: 880]
  |  Branch (581:22): [True: 0, False: 880]
  ------------------
  582|    752|		asn1_alg_id[1].flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|    752|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  583|       |
  584|  1.63k|	r = _sc_asn1_encode(ctx, asn1_alg_id, buf, len, depth + 1);
  585|  1.63k|	LOG_TEST_RET(ctx, r, "ASN.1 encode of algorithm failed");
  ------------------
  |  |  174|  1.63k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.63k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.63k|	int _ret = (r); \
  |  |  |  |  168|  1.63k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.63k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  1.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  586|       |
  587|       |	/* Encode any parameters */
  588|  1.63k|	if (id->params && alg_info->encode) {
  ------------------
  |  Branch (588:6): [True: 880, False: 752]
  |  Branch (588:20): [True: 880, False: 0]
  ------------------
  589|    880|		r = alg_info->encode(ctx, id->params, &obj, &obj_len, depth+1);
  590|    880|		if (r < 0) {
  ------------------
  |  Branch (590:7): [True: 0, False: 880]
  ------------------
  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|    880|	}
  596|       |
  597|  1.63k|	if (obj_len) {
  ------------------
  |  Branch (597:6): [True: 880, False: 752]
  ------------------
  598|    880|		tmp = (u8 *) realloc(*buf, *len + obj_len);
  599|    880|		if (!tmp) {
  ------------------
  |  Branch (599:7): [True: 0, False: 880]
  ------------------
  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|    880|		*buf = tmp;
  606|    880|		memcpy(*buf + *len, obj, obj_len);
  607|    880|		*len += obj_len;
  608|    880|		free(obj);
  609|    880|	}
  610|       |
  611|  1.63k|	sc_log(ctx, "return encoded algorithm ID: %s", sc_dump_hex(*buf, *len));
  ------------------
  |  |   71|  1.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  612|  1.63k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.63k|	int _ret = r; \
  |  |  |  |  155|  1.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.63k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.63k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.63k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.63k|	return _ret; \
  |  |  |  |  163|  1.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  613|  1.63k|}
sc_asn1_clear_algorithm_id:
  617|  6.11k|{
  618|  6.11k|	struct sc_asn1_pkcs15_algorithm_info *aip;
  619|       |
  620|  6.11k|	if (id->params && (aip = sc_asn1_get_algorithm_info(id)) && aip->free) {
  ------------------
  |  Branch (620:6): [True: 1.90k, False: 4.21k]
  |  Branch (620:20): [True: 1.90k, False: 0]
  |  Branch (620:62): [True: 1.90k, False: 0]
  ------------------
  621|  1.90k|		aip->free(id->params);
  622|       |		id->params = NULL;
  623|  1.90k|	}
  624|  6.11k|}
pkcs15-algo.c:sc_asn1_get_algorithm_info:
  486|  7.97k|{
  487|  7.97k|	struct sc_asn1_pkcs15_algorithm_info *aip = NULL;
  488|       |
  489|   103k|	for (aip = algorithm_table; aip->id >= 0; aip++)   {
  ------------------
  |  Branch (489:30): [True: 100k, False: 2.13k]
  ------------------
  490|   100k|		if ((int) id->algorithm < 0 && sc_compare_oid(&id->oid, &aip->oid))
  ------------------
  |  Branch (490:7): [True: 60.8k, False: 40.0k]
  |  Branch (490:34): [True: 2.30k, False: 58.5k]
  ------------------
  491|  2.30k|			return aip;
  492|       |
  493|  98.6k|		if (aip->id == (int)id->algorithm)
  ------------------
  |  Branch (493:7): [True: 3.53k, False: 95.0k]
  ------------------
  494|  3.53k|			return aip;
  495|  98.6k|	}
  496|       |
  497|  2.13k|	return NULL;
  498|  7.97k|}
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|     10|{
  145|     10|	struct sc_pbkdf2_params info;
  146|     10|	struct sc_asn1_entry asn1_pbkdf2_params[5];
  147|     10|	int r;
  148|       |
  149|     10|	sc_copy_asn1_entry(c_asn1_pbkdf2_params, asn1_pbkdf2_params);
  150|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 0,
  151|     10|			info.salt, &info.salt_len, 0);
  152|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 1,
  153|     10|			&info.iterations, NULL, 0);
  154|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 2,
  155|     10|			&info.key_length, NULL, 0);
  156|     10|	sc_format_asn1_entry(asn1_pbkdf2_params + 3,
  157|     10|			&info.hash_alg, NULL, 0);
  158|       |
  159|     10|	memset(&info, 0, sizeof(info));
  160|     10|	info.salt_len = sizeof(info.salt);
  161|     10|	info.hash_alg.algorithm = SC_ALGORITHM_SHA1;
  ------------------
  |  |   93|     10|#define SC_ALGORITHM_SHA1		129
  ------------------
  162|       |
  163|     10|	r = _sc_asn1_decode(ctx, asn1_pbkdf2_params, buf, buflen, NULL, NULL, 0, depth + 1);
  164|     10|	if (r < 0)
  ------------------
  |  Branch (164:6): [True: 10, False: 0]
  ------------------
  165|     10|		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|  1.06k|{
  266|  1.06k|	int r;
  267|  1.06k|	struct sc_object_id curve;
  268|  1.06k|	struct sc_asn1_entry asn1_ec_params[4];
  269|  1.06k|	struct sc_ec_parameters *ecp;
  270|       |
  271|  1.06k|	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|  1.06k|	sc_copy_asn1_entry(c_asn1_ec_params, asn1_ec_params);
  277|  1.06k|	sc_format_asn1_entry(asn1_ec_params + 1, &curve, 0, 0);
  278|       |
  279|       |	/* Some signature algorithms will not have any data */
  280|  1.06k|	if (buflen == 0 || buf == NULL)
  ------------------
  |  Branch (280:6): [True: 25, False: 1.04k]
  |  Branch (280:21): [True: 0, False: 1.04k]
  ------------------
  281|     25|		return 0;
  282|       |
  283|  1.04k|	r = sc_asn1_decode_choice(ctx, asn1_ec_params, buf, buflen, NULL, NULL);
  284|       |	/* r = index in asn1_ec_params */
  285|  1.04k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_decode_ec_params r=%d", r);
  ------------------
  |  |   70|  1.04k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  286|  1.04k|	if (r < 0)
  ------------------
  |  Branch (286:6): [True: 17, False: 1.02k]
  ------------------
  287|     17|		return r;
  288|       |
  289|  1.02k|	ecp = calloc(1, sizeof(struct sc_ec_parameters));
  290|  1.02k|	if (ecp == NULL)
  ------------------
  |  Branch (290:6): [True: 0, False: 1.02k]
  ------------------
  291|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  292|       |
  293|  1.02k|	if (r <= 1) {
  ------------------
  |  Branch (293:6): [True: 1.02k, False: 0]
  ------------------
  294|  1.02k|		ecp->der.value = malloc(buflen);
  295|  1.02k|		if (ecp->der.value == NULL) {
  ------------------
  |  Branch (295:7): [True: 0, False: 1.02k]
  ------------------
  296|      0|			free(ecp);
  297|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  298|      0|		}
  299|  1.02k|		ecp->der.len = buflen;
  300|  1.02k|		memcpy(ecp->der.value, buf, buflen);
  301|  1.02k|	}
  302|      0|	else    {
  303|      0|		r = 0;
  304|      0|	}
  305|       |
  306|  1.02k|	ecp->type = r; /* but 0 = ecparams if any, 1=named curve */
  307|  1.02k|	*paramp = ecp;
  308|  1.02k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.02k|#define SC_SUCCESS				0
  ------------------
  309|  1.02k|};
pkcs15-algo.c:asn1_encode_ec_params:
  314|    880|{
  315|    880|	 struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  316|       |
  317|       |	/* Only handle named curves. They may be absent too */
  318|    880|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_encode_ec_params() called");
  ------------------
  |  |   70|    880|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  319|    880|	*buf = NULL;
  320|    880|	*buflen = 0;
  321|    880|	if (ecp && ecp->type == 1 && ecp->der.value) { /* named curve */
  ------------------
  |  Branch (321:6): [True: 880, False: 0]
  |  Branch (321:13): [True: 880, False: 0]
  |  Branch (321:31): [True: 880, False: 0]
  ------------------
  322|    880|		*buf = malloc(ecp->der.len);
  323|    880|		if (*buf == NULL)
  ------------------
  |  Branch (323:7): [True: 0, False: 880]
  ------------------
  324|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  325|       |
  326|    880|		memcpy(*buf, ecp->der.value, ecp->der.len);
  327|    880|		*buflen = ecp->der.len;
  328|    880|	}
  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|    880|	return 0;
  334|    880|}
pkcs15-algo.c:asn1_free_ec_params:
  338|  1.90k|{
  339|  1.90k|	struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  340|       |
  341|  1.90k|	if (ecp) {
  ------------------
  |  Branch (341:6): [True: 1.90k, False: 0]
  ------------------
  342|  1.90k|		if (ecp->der.value)
  ------------------
  |  Branch (342:7): [True: 1.90k, False: 0]
  ------------------
  343|  1.90k|			free(ecp->der.value);
  344|  1.90k|		if (ecp->named_curve)
  ------------------
  |  Branch (344:7): [True: 0, False: 1.90k]
  ------------------
  345|      0|			free(ecp->named_curve);
  346|  1.90k|		free(ecp);
  347|  1.90k|	}
  348|  1.90k|}

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

sc_pkcs15_read_cached_file:
  113|  6.91k|{
  114|  6.91k|	char fname[PATH_MAX];
  115|  6.91k|	int rv;
  116|  6.91k|	FILE *f;
  117|  6.91k|	size_t count;
  118|  6.91k|	struct stat stbuf;
  119|  6.91k|	u8 *data = NULL;
  120|       |
  121|  6.91k|	if (path->len < 2)
  ------------------
  |  Branch (121:6): [True: 2.52k, False: 4.39k]
  ------------------
  122|  2.52k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  2.52k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  123|       |
  124|       |	/* Accept full path or FILE-ID path with AID */
  125|  4.39k|	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  119|  4.39k|#define SC_PATH_TYPE_PATH		2
  ------------------
              	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  117|  3.73k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (125:6): [True: 1.86k, False: 2.52k]
  |  Branch (125:44): [True: 0, False: 1.86k]
  |  Branch (125:82): [True: 507, False: 1.35k]
  ------------------
  126|    507|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    507|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  127|       |
  128|  3.88k|	sc_log(p15card->card->ctx, "try to read cache for %s", sc_print_path(path));
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
  129|  3.88k|	rv = generate_cache_filename(p15card, path, fname, sizeof(fname));
  130|  3.88k|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|  3.88k|#define SC_SUCCESS				0
  ------------------
  |  Branch (130:6): [True: 802, False: 3.08k]
  ------------------
  131|    802|		return rv;
  132|  3.08k|	sc_log(p15card->card->ctx, "read cached file %s", fname);
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
  133|       |
  134|  3.08k|	f = fopen(fname, "rb");
  135|  3.08k|	if (!f)
  ------------------
  |  Branch (135:6): [True: 2.46k, False: 620]
  ------------------
  136|  2.46k|		return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  2.46k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  137|    620|	if (fstat(fileno(f), &stbuf))   {
  ------------------
  |  Branch (137:6): [True: 0, False: 620]
  ------------------
  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|    620|	if (path->count < 0) {
  ------------------
  |  Branch (142:6): [True: 454, False: 166]
  ------------------
  143|    454|		count = stbuf.st_size;
  144|    454|	}
  145|    166|	else {
  146|    166|		count = path->count;
  147|    166|		if (path->index + count > (size_t)stbuf.st_size)   {
  ------------------
  |  Branch (147:7): [True: 149, False: 17]
  ------------------
  148|    149|			rv = SC_ERROR_FILE_NOT_FOUND; /* cache file bad? */
  ------------------
  |  |   51|    149|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  149|    149|			goto err;
  150|    149|		}
  151|       |
  152|     17|		if (0 != fseek(f, (long)path->index, SEEK_SET)) {
  ------------------
  |  Branch (152:7): [True: 0, False: 17]
  ------------------
  153|      0|			rv = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  154|      0|			goto err;
  155|      0|		}
  156|     17|	}
  157|       |
  158|    471|	if (*buf == NULL) {
  ------------------
  |  Branch (158:6): [True: 469, False: 2]
  ------------------
  159|    469|		data = malloc((size_t)stbuf.st_size);
  160|    469|		if (data == NULL)   {
  ------------------
  |  Branch (160:7): [True: 0, False: 469]
  ------------------
  161|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  162|      0|			goto err;
  163|      0|		}
  164|    469|	}
  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|    470|	if (count != fread(data, 1, count, f)) {
  ------------------
  |  Branch (173:6): [True: 0, False: 470]
  ------------------
  174|      0|		rv = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  175|      0|		goto err;
  176|      0|	}
  177|    470|	*buf = data;
  178|    470|	*bufsize = count;
  179|       |
  180|    470|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    470|#define SC_SUCCESS				0
  ------------------
  181|       |
  182|    620|err:
  183|    620|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    620|#define SC_SUCCESS				0
  ------------------
  |  Branch (183:6): [True: 150, False: 470]
  ------------------
  184|    150|		if (data != *buf) {
  ------------------
  |  Branch (184:7): [True: 1, False: 149]
  ------------------
  185|      1|			free(data);
  186|      1|		}
  187|    150|	}
  188|       |
  189|    620|	fclose(f);
  190|    620|	return rv;
  191|    470|}
sc_pkcs15_cache_file:
  196|    580|{
  197|    580|	char fname[PATH_MAX];
  198|    580|	int r;
  199|    580|	long len;
  200|    580|	FILE *f;
  201|    580|	size_t c;
  202|       |
  203|    580|	r = generate_cache_filename(p15card, path, fname, sizeof(fname));
  204|    580|	if (r != 0)
  ------------------
  |  Branch (204:6): [True: 395, False: 185]
  ------------------
  205|    395|		return r;
  206|       |
  207|    185|	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|    185|	if (f == NULL && errno == ENOENT) {
  ------------------
  |  Branch (211:6): [True: 49, False: 136]
  |  Branch (211:19): [True: 49, False: 0]
  ------------------
  212|     49|		if ((r = sc_make_cache_dir(p15card->card->ctx)) < 0)
  ------------------
  |  Branch (212:7): [True: 49, False: 0]
  ------------------
  213|     49|			return r;
  214|      0|		f = fopen(fname, "ab");
  215|      0|	}
  216|    136|	if (f == NULL)
  ------------------
  |  Branch (216:6): [True: 0, False: 136]
  ------------------
  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|    136|	len = ftell(f);
  222|    136|	if (len > path->index) {
  ------------------
  |  Branch (222:6): [True: 16, False: 120]
  ------------------
  223|       |		/* override previous cache records on this location */
  224|     16|		r = fseek(f, path->index, SEEK_SET);
  225|     16|		if (r != 0) {
  ------------------
  |  Branch (225:7): [True: 0, False: 16]
  ------------------
  226|      0|			fclose(f);
  227|      0|			return 0;
  228|      0|		}
  229|    120|	} else if (path->index > len) {
  ------------------
  |  Branch (229:13): [True: 31, False: 89]
  ------------------
  230|       |		/* We miss some bytes so we will not cache this chunk */
  231|     31|		fclose(f);
  232|     31|		return 0;
  233|     31|	}
  234|       |
  235|    105|	c = fwrite(buf, 1, bufsize, f);
  236|    105|	fclose(f);
  237|    105|	if (c != bufsize) {
  ------------------
  |  Branch (237:6): [True: 0, False: 105]
  ------------------
  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|    105|	return 0;
  245|    105|}
pkcs15-cache.c:generate_cache_filename:
   44|  4.46k|{
   45|  4.46k|	char dir[PATH_MAX];
   46|  4.46k|	char *last_update = NULL;
   47|  4.46k|	int  r;
   48|  4.46k|	unsigned u;
   49|  4.46k|	size_t change_counter;
   50|       |
   51|  4.46k|	if (p15card->tokeninfo->serial_number == NULL
  ------------------
  |  Branch (51:6): [True: 934, False: 3.53k]
  ------------------
   52|    934|			&& (p15card->card->uid.len == 0
  ------------------
  |  Branch (52:8): [True: 934, 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|    934|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    934|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   55|       |
   56|  3.53k|	if (path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  3.53k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (56:6): [True: 0, False: 3.53k]
  ------------------
   57|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   58|  3.53k|	r = sc_get_cache_dir(p15card->card->ctx, dir, sizeof(dir));
   59|  3.53k|	if (r)
  ------------------
  |  Branch (59:6): [True: 0, False: 3.53k]
  ------------------
   60|      0|		return r;
   61|  3.53k|	snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "/");
   62|       |
   63|  3.53k|	last_update = sc_pkcs15_get_lastupdate(p15card);
   64|  3.53k|	if (!last_update)
  ------------------
  |  Branch (64:6): [True: 3.49k, False: 41]
  ------------------
   65|  3.49k|		last_update = "NODATE";
   66|       |
   67|  3.53k|	if (p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (67:6): [True: 3.53k, False: 0]
  ------------------
   68|  3.53k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   69|  3.53k|				"%s_%s", p15card->tokeninfo->serial_number,
   70|  3.53k|				last_update);
   71|  3.53k|	} 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|  3.53k|	if (SC_SUCCESS == sc_card_ctl(p15card->card, SC_CARDCTL_GET_CHANGE_COUNTER, &change_counter))
  ------------------
  |  |   28|  3.53k|#define SC_SUCCESS				0
  ------------------
  |  Branch (78:6): [True: 0, False: 3.53k]
  ------------------
   79|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_%" SC_FORMAT_LEN_SIZE_T "u", change_counter);
   80|       |
   81|  3.53k|	if (path->aid.len &&
  ------------------
  |  Branch (81:6): [True: 1.66k, False: 1.86k]
  ------------------
   82|  1.66k|		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  117|  3.32k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
              		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  119|    259|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (82:4): [True: 1.40k, False: 259]
  |  Branch (82:42): [True: 10, False: 249]
  ------------------
   83|  1.41k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
   84|  11.3k|		for (u = 0; u < path->aid.len; u++)
  ------------------
  |  Branch (84:15): [True: 9.97k, False: 1.41k]
  ------------------
   85|  9.97k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   86|  9.97k|					"%02X",  path->aid.value[u]);
   87|  1.41k|	}
   88|  2.11k|	else if (path->type != SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  2.11k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (88:11): [True: 263, False: 1.85k]
  ------------------
   89|    263|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    263|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   90|    263|	}
   91|       |
   92|  3.26k|	if (path->len)   {
  ------------------
  |  Branch (92:6): [True: 3.26k, False: 0]
  ------------------
   93|  3.26k|		size_t offs = 0;
   94|       |
   95|  3.26k|		if (path->len > 2 && memcmp(path->value, "\x3F\x00", 2) == 0)
  ------------------
  |  Branch (95:7): [True: 1.85k, False: 1.41k]
  |  Branch (95:24): [True: 1.85k, False: 0]
  ------------------
   96|  1.85k|			offs = 2;
   97|  3.26k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
   98|  13.6k|		for (u = 0; u < path->len - offs; u++)
  ------------------
  |  Branch (98:15): [True: 10.3k, False: 3.26k]
  ------------------
   99|  10.3k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
  100|  10.3k|					"%02X",  path->value[u + offs]);
  101|  3.26k|	}
  102|       |
  103|  3.26k|	if (!buf)
  ------------------
  |  Branch (103:6): [True: 0, False: 3.26k]
  ------------------
  104|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  105|  3.26k|	strlcpy(buf, dir, bufsize);
  ------------------
  |  |   43|  3.26k|#define strlcpy _strlcpy
  ------------------
  106|       |
  107|  3.26k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.26k|#define SC_SUCCESS				0
  ------------------
  108|  3.26k|}

sc_pkcs15emu_cardos_init_ex:
  172|  7.76k|{
  173|  7.76k|	if (cardos_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (173:6): [True: 7.33k, False: 426]
  ------------------
  174|  7.33k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.33k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  175|       |
  176|    426|	return sc_pkcs15emu_cardos_init(p15card, aid);
  177|  7.76k|}
pkcs15-cardos.c:cardos_pkcs15emu_detect_card:
  138|  7.76k|{
  139|  7.76k|	if (p15card->card->type <  SC_CARD_TYPE_CARDOS_BASE)
  ------------------
  |  Branch (139:6): [True: 266, False: 7.49k]
  ------------------
  140|    266|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    266|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  141|       |
  142|  7.49k|	if (p15card->card->type >= SC_CARD_TYPE_CARDOS_BASE + 1000)
  ------------------
  |  Branch (142:6): [True: 7.07k, False: 426]
  ------------------
  143|  7.07k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.07k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  144|       |
  145|    426|	return SC_SUCCESS;
  ------------------
  |  |   28|    426|#define SC_SUCCESS				0
  ------------------
  146|  7.49k|}
pkcs15-cardos.c:sc_pkcs15emu_cardos_init:
  151|    426|{
  152|    426|	sc_card_t *card = p15card->card;
  153|    426|	int r;
  154|       |
  155|    426|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    426|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    426|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    426|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    426|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 426]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  156|       |
  157|    426|	r = sc_pkcs15_bind_internal(p15card, aid);
  158|    426|	LOG_TEST_RET(card->ctx, r, "sc_pkcs15_bind_internal failed");
  ------------------
  |  |  174|    426|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    426|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    426|	int _ret = (r); \
  |  |  |  |  168|    426|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 416, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|    416|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    416|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    416|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    416|		return _ret; \
  |  |  |  |  172|    416|	} \
  |  |  |  |  173|    426|} 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.36k|{
  159|  1.36k|	const u8 *rdn = NULL;
  160|  1.36k|	const u8 *next_ava = NULL;
  161|  1.36k|	size_t rdn_len = 0;
  162|  1.36k|	size_t next_ava_len = 0;
  163|  1.36k|	int rv;
  164|       |
  165|  1.36k|	rdn = sc_asn1_skip_tag(ctx, &dn, &dn_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &rdn_len);
  ------------------
  |  |  206|  1.36k|#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.36k|#define SC_ASN1_CONS			0x20000000
  ------------------
  166|  1.36k|	if (rdn == NULL)
  ------------------
  |  Branch (166:6): [True: 385, False: 978]
  ------------------
  167|  1.36k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of Distinguished Name");
  ------------------
  |  |  174|    385|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    385|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    385|	int _ret = (r); \
  |  |  |  |  168|    385|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 385, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    385|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    385|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    385|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    385|		return _ret; \
  |  |  |  |  172|    385|	} \
  |  |  |  |  173|    385|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|       |
  169|  1.82k|	for (next_ava = rdn, next_ava_len = rdn_len; next_ava_len; ) {
  ------------------
  |  Branch (169:47): [True: 1.81k, False: 10]
  ------------------
  170|  1.81k|		const u8 *ava, *dummy, *oidp;
  171|  1.81k|		struct sc_object_id oid;
  172|  1.81k|		size_t ava_len = 0, dummy_len, oid_len = 0;
  173|       |
  174|       |		/* unwrap the set and point to the next ava */
  175|  1.81k|		ava = sc_asn1_skip_tag(ctx, &next_ava, &next_ava_len, SC_ASN1_TAG_SET | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  207|  1.81k|#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.81k|#define SC_ASN1_CONS			0x20000000
  ------------------
  176|  1.81k|		if (ava == NULL)
  ------------------
  |  Branch (176:7): [True: 410, False: 1.40k]
  ------------------
  177|  1.81k|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA");
  ------------------
  |  |  174|    410|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    410|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    410|	int _ret = (r); \
  |  |  |  |  168|    410|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 410, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    410|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    410|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    410|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    410|		return _ret; \
  |  |  |  |  172|    410|	} \
  |  |  |  |  173|    410|} 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.40k|		dummy = ava; dummy_len = ava_len;
  189|  1.40k|		ava = sc_asn1_skip_tag(ctx, &dummy, &dummy_len, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ava_len);
  ------------------
  |  |  206|  1.40k|#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.40k|#define SC_ASN1_CONS			0x20000000
  ------------------
  190|  1.40k|		if (ava == NULL)
  ------------------
  |  Branch (190:7): [True: 108, False: 1.29k]
  ------------------
  191|  1.40k|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA");
  ------------------
  |  |  174|    108|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    108|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    108|	int _ret = (r); \
  |  |  |  |  168|    108|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 108, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    108|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    108|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    108|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    108|		return _ret; \
  |  |  |  |  172|    108|	} \
  |  |  |  |  173|    108|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|       |
  193|       |		/* unwrap the oid */
  194|  1.29k|		oidp = sc_asn1_skip_tag(ctx, &ava, &ava_len, SC_ASN1_TAG_OBJECT, &oid_len);
  ------------------
  |  |  200|  1.29k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
  195|  1.29k|		if (ava == NULL)
  ------------------
  |  Branch (195:7): [True: 0, False: 1.29k]
  ------------------
  196|  1.29k|			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.29k|		rv = sc_asn1_decode_object_id(oidp, oid_len, &oid);
  200|  1.29k|		if (rv != SC_SUCCESS)
  ------------------
  |  |   28|  1.29k|#define SC_SUCCESS				0
  ------------------
  |  Branch (200:7): [True: 408, False: 891]
  ------------------
  201|  1.29k|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA OID");
  ------------------
  |  |  174|    408|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    408|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    408|	int _ret = (r); \
  |  |  |  |  168|    408|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 408, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    408|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    408|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    408|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    408|		return _ret; \
  |  |  |  |  172|    408|	} \
  |  |  |  |  173|    408|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|       |
  203|    891|		if (sc_compare_oid(&oid, type) == 0)
  ------------------
  |  Branch (203:7): [True: 849, False: 42]
  ------------------
  204|    849|			continue;
  205|       |
  206|       |		/* Yes, then return the name */
  207|     42|		dummy = sc_asn1_skip_tag(ctx, &ava, &ava_len, ava[0] & SC_ASN1_TAG_PRIMITIVE, &dummy_len);
  ------------------
  |  |  191|     42|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  208|     42|		if (dummy == NULL)
  ------------------
  |  Branch (208:7): [True: 13, False: 29]
  ------------------
  209|     42|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "ASN.1 decoding of AVA name");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  210|     29|		if (*name == NULL) {
  ------------------
  |  Branch (210:7): [True: 29, False: 0]
  ------------------
  211|     29|			*name = malloc(dummy_len);
  212|     29|			if (*name == NULL)
  ------------------
  |  Branch (212:8): [True: 0, False: 29]
  ------------------
  213|     29|				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|     29|			*name_len = dummy_len;
  215|     29|		}
  216|       |
  217|     29|		*name_len = MIN(dummy_len, *name_len);
  ------------------
  |  |   70|     29|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 29]
  |  |  ------------------
  ------------------
  218|     29|		memcpy(*name, dummy, *name_len);
  219|     29|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 29]
  |  |  |  |  ------------------
  |  |  |  |  157|     29|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     29|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     29|	return _ret; \
  |  |  |  |  163|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  220|     29|	}
  221|       |
  222|     10|	LOG_FUNC_RETURN(ctx, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  223|     10|}
sc_pkcs15_get_extension:
  248|  1.37k|{
  249|  1.37k|	const u8 *ext = NULL;
  250|  1.37k|	const u8 *next_ext = NULL;
  251|  1.37k|	size_t ext_len = 0;
  252|  1.37k|	size_t next_ext_len = 0;
  253|  1.37k|	struct sc_object_id oid;
  254|  1.37k|	u8 *val = NULL;
  255|  1.37k|	size_t val_len = 0;
  256|  1.37k|	int critical;
  257|  1.37k|	int r;
  258|  1.37k|	struct sc_asn1_entry asn1_cert_ext[] = {
  259|  1.37k|		{ "x509v3 entry OID", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, &oid, 0 },
  ------------------
  |  |  159|  1.37k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "x509v3 entry OID", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, 0, &oid, 0 },
  ------------------
  |  |  200|  1.37k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
  260|  1.37k|		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  153|  1.37k|#define SC_ASN1_BOOLEAN                 1
  ------------------
              		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  195|  1.37k|#define SC_ASN1_TAG_BOOLEAN		1
  ------------------
              		{ "criticalFlag",  SC_ASN1_BOOLEAN, SC_ASN1_TAG_BOOLEAN, SC_ASN1_OPTIONAL, &critical, NULL },
  ------------------
  |  |  148|  1.37k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  261|  1.37k|		{ "extensionValue",SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, &val, &val_len },
  ------------------
  |  |  157|  1.37k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "extensionValue",SC_ASN1_OCTET_STRING, SC_ASN1_TAG_OCTET_STRING, SC_ASN1_ALLOC, &val, &val_len },
  ------------------
  |  |  198|  1.37k|#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.37k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  262|  1.37k|		{ NULL, 0, 0, 0, NULL, NULL }
  263|  1.37k|	};
  264|       |
  265|  1.37k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.37k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.37k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.37k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.37k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.37k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|       |
  267|  1.38k|	for (next_ext = cert->extensions, next_ext_len = cert->extensions_len; next_ext_len; ) {
  ------------------
  |  Branch (267:73): [True: 75, False: 1.30k]
  ------------------
  268|       |		/* unwrap the set and point to the next ava */
  269|     75|		ext = sc_asn1_skip_tag(ctx, &next_ext, &next_ext_len,
  270|     75|			SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ext_len);
  ------------------
  |  |  206|     75|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              			SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &ext_len);
  ------------------
  |  |  141|     75|#define SC_ASN1_CONS			0x20000000
  ------------------
  271|     75|		if (ext == NULL)
  ------------------
  |  Branch (271:7): [True: 7, False: 68]
  ------------------
  272|     75|			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|     68|		critical = 0;
  280|     68|		r = sc_asn1_decode(ctx, asn1_cert_ext, ext, ext_len, NULL, NULL);
  281|     68|		if (r < 0)
  ------------------
  |  Branch (281:7): [True: 8, False: 60]
  ------------------
  282|     68|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      8|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      8|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      8|	int _ret = r; \
  |  |  |  |  155|      8|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  283|       |
  284|       |		/* is it the RN we are looking for */
  285|     60|		if (sc_compare_oid(&oid, type) != 0) {
  ------------------
  |  Branch (285:7): [True: 48, False: 12]
  ------------------
  286|     48|			if (*ext_val == NULL) {
  ------------------
  |  Branch (286:8): [True: 48, False: 0]
  ------------------
  287|     48|				*ext_val = val;
  288|     48|				val = NULL;
  289|     48|				*ext_val_len = val_len;
  290|       |				/* do not free here -- return the allocated value to caller */
  291|     48|			}
  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|     48|			if (is_critical)
  ------------------
  |  Branch (300:8): [True: 0, False: 48]
  ------------------
  301|      0|				*is_critical = critical;
  302|       |
  303|     48|			r = (int)val_len;
  304|     48|			LOG_FUNC_RETURN(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: 1, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  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|     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|     48|	return _ret; \
  |  |  |  |  163|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|     48|		}
  306|     12|		if (val) {
  ------------------
  |  Branch (306:7): [True: 11, False: 1]
  ------------------
  307|     11|			free(val);
  308|     11|			val = NULL;
  309|     11|		}
  310|     12|	}
  311|  1.30k|	if (val)
  ------------------
  |  Branch (311:6): [True: 0, False: 1.30k]
  ------------------
  312|      0|	    free(val);
  313|       |
  314|  1.30k|	LOG_FUNC_RETURN(ctx, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|  1.30k|}
sc_pkcs15_get_bitstring_extension:
  325|  1.37k|{
  326|  1.37k|	int r;
  327|  1.37k|	u8 *bit_string = NULL;
  328|  1.37k|	size_t bit_string_len=0, val_len = sizeof(*value);
  329|  1.37k|	struct sc_asn1_entry asn1_bit_string[] = {
  330|  1.37k|		{ "bitString", SC_ASN1_BIT_FIELD, SC_ASN1_TAG_BIT_STRING, 0, value, &val_len },
  ------------------
  |  |  171|  1.37k|#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.37k|#define SC_ASN1_TAG_BIT_STRING		3
  ------------------
  331|  1.37k|		{ NULL, 0, 0, 0, NULL, NULL }
  332|  1.37k|	};
  333|       |
  334|  1.37k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.37k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.37k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.37k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.37k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.37k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|       |
  336|  1.37k|	r = sc_pkcs15_get_extension(ctx, cert, type, &bit_string, &bit_string_len, is_critical);
  337|  1.37k|	LOG_TEST_RET(ctx, r, "Get extension error");
  ------------------
  |  |  174|  1.37k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.37k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.37k|	int _ret = (r); \
  |  |  |  |  168|  1.37k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.32k, False: 48]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.32k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.32k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.32k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.32k|		return _ret; \
  |  |  |  |  172|  1.32k|	} \
  |  |  |  |  173|  1.37k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  338|       |
  339|     48|	r = sc_asn1_decode(ctx, asn1_bit_string, bit_string, bit_string_len, NULL, NULL);
  340|     48|	free(bit_string);
  341|     48|	LOG_TEST_RET(ctx, r, "Decoding extension bit string");
  ------------------
  |  |  174|     48|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     48|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     48|	int _ret = (r); \
  |  |  |  |  168|     48|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 46]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  342|       |
  343|     46|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     46|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     46|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     46|	int _ret = r; \
  |  |  |  |  155|     46|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 46, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  157|     46|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     46|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     46|	return _ret; \
  |  |  |  |  163|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  344|     46|}
sc_pkcs15_read_certificate:
  371|  4.11k|{
  372|  4.11k|	struct sc_context *ctx = NULL;
  373|  4.11k|	struct sc_pkcs15_cert *cert = NULL;
  374|  4.11k|	struct sc_pkcs15_der der;
  375|  4.11k|	int r;
  376|       |
  377|  4.11k|	if (p15card == NULL || info == NULL || cert_out == NULL) {
  ------------------
  |  Branch (377:6): [True: 0, False: 4.11k]
  |  Branch (377:25): [True: 0, False: 4.11k]
  |  Branch (377:41): [True: 0, False: 4.11k]
  ------------------
  378|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  379|      0|	}
  380|  4.11k|	ctx = p15card->card->ctx;
  381|  4.11k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.11k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.11k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.11k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.11k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.11k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|  4.11k|	if (info->value.len && info->value.value)   {
  ------------------
  |  Branch (383:6): [True: 2.93k, False: 1.18k]
  |  Branch (383:25): [True: 2.93k, False: 0]
  ------------------
  384|  2.93k|		sc_der_copy(&der, &info->value);
  385|  2.93k|	}
  386|  1.18k|	else if (info->path.len) {
  ------------------
  |  Branch (386:11): [True: 1.02k, False: 159]
  ------------------
  387|  1.02k|		r = sc_pkcs15_read_file(p15card, &info->path, &der.value, &der.len, private_obj);
  388|  1.02k|		LOG_TEST_RET(ctx, r, "Unable to read certificate file.");
  ------------------
  |  |  174|  1.02k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.02k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.02k|	int _ret = (r); \
  |  |  |  |  168|  1.02k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 798, False: 223]
  |  |  |  |  ------------------
  |  |  |  |  169|    798|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    798|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    798|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    798|		return _ret; \
  |  |  |  |  172|    798|	} \
  |  |  |  |  173|  1.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 223]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  389|  1.02k|	}
  390|    159|	else   {
  391|    159|		LOG_FUNC_RETURN(ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|    159|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    159|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    159|	int _ret = r; \
  |  |  |  |  155|    159|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 159, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    159|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    159|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 159, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    159|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    159|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    159|	return _ret; \
  |  |  |  |  163|    159|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|    159|	}
  393|       |
  394|  3.15k|	cert = malloc(sizeof(struct sc_pkcs15_cert));
  395|  3.15k|	if (cert == NULL) {
  ------------------
  |  Branch (395:6): [True: 0, False: 3.15k]
  ------------------
  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|  3.15k|	memset(cert, 0, sizeof(struct sc_pkcs15_cert));
  400|  3.15k|	if (parse_x509_cert(ctx, &der, cert)) {
  ------------------
  |  Branch (400:6): [True: 1.16k, False: 1.98k]
  ------------------
  401|  1.16k|		free(der.value);
  402|  1.16k|		sc_pkcs15_free_certificate(cert);
  403|  1.16k|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  164|  1.16k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.16k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.16k|	int _ret = r; \
  |  |  |  |  155|  1.16k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.16k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.16k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.16k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.16k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.16k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.16k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.16k|	return _ret; \
  |  |  |  |  163|  1.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  404|  1.16k|	}
  405|  1.98k|	free(der.value);
  406|       |
  407|  1.98k|	*cert_out = cert;
  408|  1.98k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.98k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.98k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.98k|	int _ret = r; \
  |  |  |  |  155|  1.98k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.98k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.98k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.98k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.98k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.98k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.98k|	return _ret; \
  |  |  |  |  163|  1.98k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  409|  1.98k|}
sc_pkcs15_decode_cdf_entry:
  446|     67|{
  447|     67|	sc_context_t *ctx = p15card->card->ctx;
  448|     67|	struct sc_pkcs15_cert_info info;
  449|     67|	struct sc_asn1_entry	asn1_cred_ident[3], asn1_com_cert_attr[4],
  450|     67|				asn1_x509_cert_attr[2], asn1_type_cert_attr[2],
  451|     67|				asn1_cert[2], asn1_x509_cert_value_choice[3];
  452|     67|	struct sc_asn1_pkcs15_object cert_obj = {
  453|     67|		obj, asn1_com_cert_attr, NULL,
  454|     67|		asn1_type_cert_attr };
  455|     67|	sc_pkcs15_der_t *der = &info.value;
  456|     67|	u8 id_value[128];
  457|     67|	int id_type;
  458|     67|	size_t id_value_len = sizeof(id_value);
  459|     67|	int r;
  460|       |
  461|     67|	sc_copy_asn1_entry(c_asn1_cred_ident, asn1_cred_ident);
  462|     67|	sc_copy_asn1_entry(c_asn1_com_cert_attr, asn1_com_cert_attr);
  463|     67|	sc_copy_asn1_entry(c_asn1_x509_cert_attr, asn1_x509_cert_attr);
  464|     67|	sc_copy_asn1_entry(c_asn1_x509_cert_value_choice, asn1_x509_cert_value_choice);
  465|     67|	sc_copy_asn1_entry(c_asn1_type_cert_attr, asn1_type_cert_attr);
  466|     67|	sc_copy_asn1_entry(c_asn1_cert, asn1_cert);
  467|       |
  468|     67|	sc_format_asn1_entry(asn1_cred_ident + 0, &id_type, NULL, 0);
  469|     67|	sc_format_asn1_entry(asn1_cred_ident + 1, &id_value, &id_value_len, 0);
  470|     67|	sc_format_asn1_entry(asn1_com_cert_attr + 0, &info.id, NULL, 0);
  471|     67|	sc_format_asn1_entry(asn1_com_cert_attr + 1, &info.authority, NULL, 0);
  472|     67|	sc_format_asn1_entry(asn1_com_cert_attr + 2, asn1_cred_ident, NULL, 0);
  473|     67|	sc_format_asn1_entry(asn1_x509_cert_attr + 0, asn1_x509_cert_value_choice, NULL, 0);
  474|     67|	sc_format_asn1_entry(asn1_x509_cert_value_choice + 0, &info.path, NULL, 0);
  475|     67|	sc_format_asn1_entry(asn1_x509_cert_value_choice + 1, &der->value, &der->len, 0);
  476|     67|	sc_format_asn1_entry(asn1_type_cert_attr + 0, asn1_x509_cert_attr, NULL, 0);
  477|     67|	sc_format_asn1_entry(asn1_cert + 0, &cert_obj, NULL, 0);
  478|       |
  479|       |	/* Fill in defaults */
  480|     67|	memset(&info, 0, sizeof(info));
  481|     67|	info.authority = 0;
  482|       |
  483|     67|	r = sc_asn1_decode(ctx, asn1_cert, *buf, *buflen, buf, buflen);
  484|       |	/* In case of error, trash the cert value (direct coding) */
  485|     67|	if (r < 0 && der->value)
  ------------------
  |  Branch (485:6): [True: 67, False: 0]
  |  Branch (485:15): [True: 0, False: 67]
  ------------------
  486|      0|		free(der->value);
  487|     67|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     67|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (487:6): [True: 6, False: 61]
  ------------------
  488|      6|		return r;
  489|     61|	LOG_TEST_RET(ctx, r, "ASN.1 decoding 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: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     61|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     61|		return _ret; \
  |  |  |  |  172|     61|	} \
  |  |  |  |  173|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    134|{
  614|    134|	unsigned int pub_usage = 0, pr_usage = 0;
  615|    134|	unsigned int alg_flags = sc_pkcs15_alg_flags_from_algorithm(algorithm);
  616|       |
  617|    134|	if (cert_usage & SC_PKCS15_X509_USAGE_SIGNATURE) {
  ------------------
  |  |  592|    134|	(SC_X509_DIGITAL_SIGNATURE | \
  |  |  ------------------
  |  |  |  |  614|    134|#define SC_X509_DIGITAL_SIGNATURE     0x0001UL
  |  |  ------------------
  |  |  593|    134|	SC_X509_NON_REPUDIATION    | \
  |  |  ------------------
  |  |  |  |  615|    134|#define SC_X509_NON_REPUDIATION       0x0002UL
  |  |  ------------------
  |  |  594|    134|	SC_X509_KEY_CERT_SIGN      | \
  |  |  ------------------
  |  |  |  |  619|    134|#define SC_X509_KEY_CERT_SIGN         0x0020UL
  |  |  ------------------
  |  |  595|    134|	SC_X509_CRL_SIGN)
  |  |  ------------------
  |  |  |  |  620|    134|#define SC_X509_CRL_SIGN              0x0040UL
  |  |  ------------------
  ------------------
  |  Branch (617:6): [True: 91, False: 43]
  ------------------
  618|     91|		pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  311|     91|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
              		pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY|SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|     91|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  619|     91|		pr_usage |= SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  307|     91|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		pr_usage |= SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|     91|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  620|     91|	}
  621|    134|	if (cert_usage & SC_PKCS15_X509_USAGE_DERIVE) {
  ------------------
  |  |  597|    134|	(SC_X509_KEY_ENCIPHERMENT | \
  |  |  ------------------
  |  |  |  |  616|    134|#define SC_X509_KEY_ENCIPHERMENT      0x0004UL
  |  |  ------------------
  |  |  598|    134|			SC_X509_KEY_AGREEMENT)
  |  |  ------------------
  |  |  |  |  618|    134|#define SC_X509_KEY_AGREEMENT         0x0010UL
  |  |  ------------------
  ------------------
  |  Branch (621:6): [True: 43, False: 91]
  ------------------
  622|     43|		pub_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|     43|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  623|     43|		pr_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|     43|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  624|     43|	}
  625|    134|	if (cert_usage & (SC_PKCS15_X509_USAGE_DECRYPT|SC_PKCS15_X509_USAGE_UNWRAP)) {
  ------------------
  |  |  603|    134|	(SC_X509_DATA_ENCIPHERMENT | \
  |  |  ------------------
  |  |  |  |  617|    134|#define SC_X509_DATA_ENCIPHERMENT     0x0008UL
  |  |  ------------------
  |  |  604|    134|	SC_X509_ENCIPHER_ONLY)
  |  |  ------------------
  |  |  |  |  621|    134|#define SC_X509_ENCIPHER_ONLY         0x0080UL
  |  |  ------------------
  ------------------
              	if (cert_usage & (SC_PKCS15_X509_USAGE_DECRYPT|SC_PKCS15_X509_USAGE_UNWRAP)) {
  ------------------
  |  |  600|    134|	(SC_X509_KEY_ENCIPHERMENT | \
  |  |  ------------------
  |  |  |  |  616|    134|#define SC_X509_KEY_ENCIPHERMENT      0x0004UL
  |  |  ------------------
  |  |  601|    134|	SC_X509_KEY_AGREEMENT)
  |  |  ------------------
  |  |  |  |  618|    134|#define SC_X509_KEY_AGREEMENT         0x0010UL
  |  |  ------------------
  ------------------
  |  Branch (625:6): [True: 131, False: 3]
  ------------------
  626|    131|		pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|    131|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  627|    131|		pr_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|    131|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  628|    131|	}
  629|    134|	if (allow_nonrepudiation && (cert_usage & SC_PKCS15_X509_USAGE_NONREPUDIATION)) {
  ------------------
  |  |  606|    134|	SC_X509_NON_REPUDIATION
  |  |  ------------------
  |  |  |  |  615|    134|#define SC_X509_NON_REPUDIATION       0x0002UL
  |  |  ------------------
  ------------------
  |  Branch (629:6): [True: 134, False: 0]
  |  Branch (629:30): [True: 3, False: 131]
  ------------------
  630|      3|		pub_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      3|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  631|      3|		pr_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      3|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  632|      3|	}
  633|       |	/* filter usages algorithm */
  634|    134|	if (pub_usage_ptr) {
  ------------------
  |  Branch (634:6): [True: 134, False: 0]
  ------------------
  635|    134|		*pub_usage_ptr = pub_usage & alg_flags;
  636|    134|	}
  637|    134|	if (pr_usage_ptr) {
  ------------------
  |  Branch (637:6): [True: 134, False: 0]
  ------------------
  638|    134|		*pr_usage_ptr = pr_usage & alg_flags;
  639|    134|	}
  640|    134|	return SC_SUCCESS;
  ------------------
  |  |   28|    134|#define SC_SUCCESS				0
  ------------------
  641|    134|}
sc_pkcs15_free_certificate:
  645|  3.15k|{
  646|  3.15k|	if (cert == NULL) {
  ------------------
  |  Branch (646:6): [True: 0, False: 3.15k]
  ------------------
  647|      0|		return;
  648|      0|	}
  649|       |
  650|  3.15k|	sc_pkcs15_free_pubkey(cert->key);
  651|  3.15k|	free(cert->subject);
  652|  3.15k|	free(cert->issuer);
  653|  3.15k|	free(cert->serial);
  654|  3.15k|	free(cert->data.value);
  655|  3.15k|	free(cert->extensions);
  656|  3.15k|	free(cert);
  657|  3.15k|}
sc_pkcs15_free_cert_info:
  662|  3.47k|{
  663|  3.47k|	if (!cert)
  ------------------
  |  Branch (663:6): [True: 0, False: 3.47k]
  ------------------
  664|      0|		return;
  665|  3.47k|	free(cert->value.value);
  666|  3.47k|	free(cert);
  667|  3.47k|}
pkcs15-cert.c:parse_x509_cert:
   40|  3.15k|{
   41|  3.15k|	int r;
   42|  3.15k|	struct sc_algorithm_id sig_alg = {0};
   43|  3.15k|	struct sc_pkcs15_pubkey *pubkey = NULL;
   44|  3.15k|	unsigned char *serial = NULL, *issuer = NULL, *subject = NULL, *buf =  der->value;
   45|  3.15k|	size_t serial_len = 0, issuer_len = 0, subject_len = 0, data_len = 0, buflen = der->len;
   46|  3.15k|	struct sc_asn1_entry asn1_version[] = {
   47|  3.15k|		{ "version", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, 0, &cert->version, NULL },
  ------------------
  |  |  154|  3.15k|#define SC_ASN1_INTEGER                 2
  ------------------
              		{ "version", SC_ASN1_INTEGER, SC_ASN1_TAG_INTEGER, 0, &cert->version, NULL },
  ------------------
  |  |  196|  3.15k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
   48|  3.15k|		{ NULL, 0, 0, 0, NULL, NULL }
   49|  3.15k|	};
   50|  3.15k|	struct sc_asn1_entry asn1_extensions[] = {
   51|  3.15k|		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  157|  3.15k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  148|  3.15k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              		{ "x509v3",		SC_ASN1_OCTET_STRING,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL| SC_ASN1_ALLOC, &cert->extensions, &cert->extensions_len },
  ------------------
  |  |  149|  3.15k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   52|  3.15k|		{ NULL, 0, 0, 0, NULL, NULL }
   53|  3.15k|	};
   54|  3.15k|	struct sc_asn1_entry asn1_tbscert[] = {
   55|  3.15k|		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  169|  3.15k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  139|  3.15k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "version",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
  ------------------
  |  |  148|  3.15k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
   56|  3.15k|		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  157|  3.15k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  196|  3.15k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
              		{ "serialNumber",	SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, &serial, &serial_len },
  ------------------
  |  |  149|  3.15k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   57|  3.15k|		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  169|  3.15k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "signature",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
   58|  3.15k|		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  157|  3.15k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "issuer",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &issuer, &issuer_len },
  ------------------
  |  |  149|  3.15k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   59|  3.15k|		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  169|  3.15k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "validity",		SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
   60|  3.15k|		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  157|  3.15k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "subject",		SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &subject, &subject_len },
  ------------------
  |  |  149|  3.15k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   61|       |		/* Use a callback to get the algorithm, parameters and pubkey into sc_pkcs15_pubkey */
   62|  3.15k|		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  181|  3.15k|#define SC_ASN1_CALLBACK		384
  ------------------
              		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subjectPublicKeyInfo",SC_ASN1_CALLBACK, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, sc_pkcs15_pubkey_from_spki_fields,  &pubkey },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
   63|  3.15k|		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  169|  3.15k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  139|  3.15k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "extensions",		SC_ASN1_STRUCT,    SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
  ------------------
  |  |  148|  3.15k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
   64|  3.15k|		{ NULL, 0, 0, 0, NULL, NULL }
   65|  3.15k|	};
   66|  3.15k|	struct sc_asn1_entry asn1_cert[] = {
   67|  3.15k|		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  169|  3.15k|#define SC_ASN1_STRUCT			129
  ------------------
              		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "tbsCertificate",	SC_ASN1_STRUCT,    SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
   68|  3.15k|		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  177|  3.15k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
              		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "signatureAlgorithm",	SC_ASN1_ALGORITHM_ID, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
   69|  3.15k|		{ "signatureValue",	SC_ASN1_BIT_STRING, SC_ASN1_TAG_BIT_STRING, 0, NULL, NULL },
  ------------------
  |  |  155|  3.15k|#define SC_ASN1_BIT_STRING              3
  ------------------
              		{ "signatureValue",	SC_ASN1_BIT_STRING, SC_ASN1_TAG_BIT_STRING, 0, NULL, NULL },
  ------------------
  |  |  197|  3.15k|#define SC_ASN1_TAG_BIT_STRING		3
  ------------------
   70|  3.15k|		{ NULL, 0, 0, 0, NULL, NULL }
   71|  3.15k|	};
   72|  3.15k|	struct sc_asn1_entry asn1_serial_number[] = {
   73|  3.15k|		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  3.15k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  196|  3.15k|#define SC_ASN1_TAG_INTEGER		2
  ------------------
              		{ "serialNumber", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  3.15k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   74|  3.15k|		{ NULL, 0, 0, 0, NULL, NULL }
   75|  3.15k|	};
   76|  3.15k|	struct sc_asn1_entry asn1_subject[] = {
   77|  3.15k|		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  3.15k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "subject", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  3.15k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   78|  3.15k|		{ NULL, 0, 0, 0, NULL, NULL }
   79|  3.15k|	};
   80|  3.15k|	struct sc_asn1_entry asn1_issuer[] = {
   81|  3.15k|		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  157|  3.15k|#define SC_ASN1_OCTET_STRING            4
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "issuer", SC_ASN1_OCTET_STRING, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  3.15k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
   82|  3.15k|		{ NULL, 0, 0, 0, NULL, NULL }
   83|  3.15k|	};
   84|       |
   85|  3.15k|	const u8 *obj;
   86|  3.15k|	size_t objlen;
   87|       |
   88|  3.15k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.15k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.15k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.15k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.15k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|       |
   90|  3.15k|	memset(cert, 0, sizeof(*cert));
   91|  3.15k|	obj = sc_asn1_verify_tag(ctx, buf, buflen, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &objlen);
  ------------------
  |  |  206|  3.15k|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
              	obj = sc_asn1_verify_tag(ctx, buf, buflen, SC_ASN1_TAG_SEQUENCE | SC_ASN1_CONS, &objlen);
  ------------------
  |  |  141|  3.15k|#define SC_ASN1_CONS			0x20000000
  ------------------
   92|  3.15k|	if (obj == NULL)
  ------------------
  |  Branch (92:6): [True: 444, False: 2.71k]
  ------------------
   93|  3.15k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "X.509 certificate not found");
  ------------------
  |  |  174|    444|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    444|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    444|	int _ret = (r); \
  |  |  |  |  168|    444|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 444, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    444|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    444|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    444|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    444|		return _ret; \
  |  |  |  |  172|    444|	} \
  |  |  |  |  173|    444|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   94|       |
   95|  2.71k|	data_len = objlen + (obj - buf);
   96|  2.71k|	cert->data.value = malloc(data_len);
   97|  2.71k|	if (!cert->data.value)
  ------------------
  |  Branch (97:6): [True: 0, False: 2.71k]
  ------------------
   98|  2.71k|		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.71k|	memcpy(cert->data.value, buf, data_len);
  100|  2.71k|	cert->data.len = data_len;
  101|       |
  102|  2.71k|	r = sc_asn1_decode(ctx, asn1_cert, obj, objlen, NULL, NULL);
  103|  2.71k|	cert->key = pubkey;
  104|  2.71k|	cert->version++;
  105|       |
  106|  2.71k|	LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of certificate failed");
  ------------------
  |  |  184|  2.71k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.71k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.71k|	int _ret = (r); \
  |  |  |  |  178|  2.71k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 722, False: 1.98k]
  |  |  |  |  ------------------
  |  |  |  |  179|    722|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    722|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    722|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    722|		goto err; \
  |  |  |  |  182|    722|	} \
  |  |  |  |  183|  2.71k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.98k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|       |
  108|  1.98k|	if (!pubkey)
  ------------------
  |  Branch (108:6): [True: 12, False: 1.97k]
  ------------------
  109|  1.98k|		LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_ASN1_OBJECT, "Unable to decode subjectPublicKeyInfo from cert");
  ------------------
  |  |  184|     12|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     12|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     12|	int _ret = (r); \
  |  |  |  |  178|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     12|		goto err; \
  |  |  |  |  182|     12|	} \
  |  |  |  |  183|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  110|       |
  111|       |
  112|  1.97k|	if (serial && serial_len)   {
  ------------------
  |  Branch (112:6): [True: 1.59k, False: 378]
  |  Branch (112:16): [True: 1.59k, False: 0]
  ------------------
  113|  1.59k|		sc_format_asn1_entry(asn1_serial_number + 0, serial, &serial_len, 1);
  114|  1.59k|		r = sc_asn1_encode(ctx, asn1_serial_number, &cert->serial, &cert->serial_len);
  115|  1.59k|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of serial failed");
  ------------------
  |  |  184|  1.59k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.59k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.59k|	int _ret = (r); \
  |  |  |  |  178|  1.59k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 1.59k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.59k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.59k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  116|  1.59k|	}
  117|       |
  118|  1.97k|	if (subject && subject_len)   {
  ------------------
  |  Branch (118:6): [True: 1.59k, False: 385]
  |  Branch (118:17): [True: 1.59k, False: 0]
  ------------------
  119|  1.59k|		sc_format_asn1_entry(asn1_subject + 0, subject, &subject_len, 1);
  120|  1.59k|		r = sc_asn1_encode(ctx, asn1_subject, &cert->subject, &cert->subject_len);
  121|  1.59k|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of subject");
  ------------------
  |  |  184|  1.59k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.59k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.59k|	int _ret = (r); \
  |  |  |  |  178|  1.59k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 1.59k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.59k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.59k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|  1.59k|	}
  123|       |
  124|  1.97k|	if (issuer && issuer_len)   {
  ------------------
  |  Branch (124:6): [True: 741, False: 1.23k]
  |  Branch (124:16): [True: 741, False: 0]
  ------------------
  125|    741|		sc_format_asn1_entry(asn1_issuer + 0, issuer, &issuer_len, 1);
  126|    741|		r = sc_asn1_encode(ctx, asn1_issuer, &cert->issuer, &cert->issuer_len);
  127|    741|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 encoding of issuer");
  ------------------
  |  |  184|    741|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    741|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    741|	int _ret = (r); \
  |  |  |  |  178|    741|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 741]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    741|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 741]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|    741|	}
  129|       |
  130|  2.71k|err:
  131|       |	/* not used for anything */
  132|  2.71k|	sc_asn1_clear_algorithm_id(&sig_alg);
  133|  2.71k|	free(serial);
  134|  2.71k|	free(subject);
  135|  2.71k|	free(issuer);
  136|       |
  137|  2.71k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  2.71k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.71k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.71k|	int _ret = r; \
  |  |  |  |  155|  2.71k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.71k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.71k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    722|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 722, False: 1.98k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.71k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.71k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.71k|	return _ret; \
  |  |  |  |  163|  2.71k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|  2.71k|}
pkcs15-cert.c:sc_pkcs15_alg_flags_from_algorithm:
  568|    134|{
  569|    134|	switch (algorithm) {
  ------------------
  |  Branch (569:10): [True: 134, False: 0]
  ------------------
  570|    133|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|    133|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (570:2): [True: 133, False: 1]
  ------------------
  571|    133|		return SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP |
  ------------------
  |  |  305|    133|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              		return SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP |
  ------------------
  |  |  309|    133|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  572|    133|		       SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER |
  ------------------
  |  |  311|    133|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER |
  ------------------
  |  |  312|    133|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  573|    133|		       SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP |
  ------------------
  |  |  306|    133|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP |
  ------------------
  |  |  310|    133|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  574|    133|		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER |
  ------------------
  |  |  307|    133|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER |
  ------------------
  |  |  308|    133|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  575|    133|		       SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|    133|#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|      1|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|      1|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (580:2): [True: 1, False: 133]
  ------------------
  581|      1|		return SC_PKCS15_PRKEY_USAGE_DERIVE | SC_PKCS15_PRKEY_USAGE_VERIFY|
  ------------------
  |  |  313|      1|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
              		return SC_PKCS15_PRKEY_USAGE_DERIVE | SC_PKCS15_PRKEY_USAGE_VERIFY|
  ------------------
  |  |  311|      1|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  582|      1|		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  307|      1|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              		       SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      1|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  583|      0|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   80|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (583:2): [True: 0, False: 134]
  ------------------
  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|    134|	}
  587|      0|	return 0;
  588|    134|}

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

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

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

sc_pkcs15emu_dnie_init_ex:
  281|  10.0k|{
  282|  10.0k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  10.0k|#define SC_SUCCESS				0
  ------------------
  283|  10.0k|	sc_context_t *ctx = p15card->card->ctx;
  284|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|       |
  286|  10.0k|#if defined(ENABLE_OPENSSL) && defined(ENABLE_SM)
  287|       |	/* check for proper card */
  288|  10.0k|	r = dnie_match_card(p15card->card);
  289|  10.0k|	if (r == 0)
  ------------------
  |  Branch (289:6): [True: 9.57k, False: 524]
  ------------------
  290|  10.0k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  9.57k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.57k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.57k|	int _ret = r; \
  |  |  |  |  155|  9.57k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.57k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.57k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  9.57k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.57k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.57k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.57k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  9.57k|	return _ret; \
  |  |  |  |  163|  9.57k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |	/* ok: initialize and return */
  292|    524|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_dnie_init(p15card));
  ------------------
  |  |  164|    524|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    524|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    524|	int _ret = r; \
  |  |  |  |  155|    524|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 524, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    524|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    524|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 524, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    524|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    524|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    524|	return _ret; \
  |  |  |  |  163|    524|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  293|       |#else
  294|       |	r = SC_ERROR_WRONG_CARD;
  295|       |	LOG_FUNC_RETURN(ctx, r);
  296|       |#endif
  297|    524|}
pkcs15-dnie.c:sc_pkcs15emu_dnie_init:
  139|    524|{
  140|    524|	u8 buf[1024];
  141|    524|	sc_pkcs15_df_t *df;
  142|    524|	sc_pkcs15_object_t *p15_obj;
  143|    524|	size_t len = sizeof(buf);
  144|    524|	int rv;
  145|    524|	struct sc_pkcs15_cert_info *p15_info = NULL;
  146|    524|	int use_pin_cache_backup = p15card->opts.use_pin_cache;
  147|       |
  148|    524|	sc_context_t *ctx = p15card->card->ctx;
  149|    524|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    524|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    524|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    524|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    524|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 524]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|       |
  151|       |	/* Check for correct card driver (i.e. iso7816) */
  152|    524|	if (strcmp(p15card->card->driver->short_name, "dnie") != 0)
  ------------------
  |  Branch (152:6): [True: 3, False: 521]
  ------------------
  153|      3|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      3|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  154|       |
  155|       |	/* Check for correct card atr */
  156|    521|	if (dnie_match_card(p15card->card) != 1)
  ------------------
  |  Branch (156:6): [True: 0, False: 521]
  ------------------
  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|    521|	if (p15card->card->atr.value[15] >= DNIE_30_VERSION) {
  ------------------
  |  |  100|    521|#define DNIE_30_VERSION 0x04
  ------------------
  |  Branch (162:6): [True: 485, False: 36]
  ------------------
  163|    485|		p15card->opts.use_pin_cache = 1;
  164|    485|		p15card->opts.pin_cache_counter = DNIE_30_CACHE_COUNTER;
  ------------------
  |  |  101|    485|#define DNIE_30_CACHE_COUNTER 30000
  ------------------
  165|    485|		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|    485|#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|    485|			p15card->opts.use_file_cache,
  167|    485|			p15card->opts.use_pin_cache,
  168|    485|			p15card->opts.pin_cache_counter,
  169|    485|			p15card->opts.pin_cache_ignore_user_consent);
  170|    485|        }
  171|       |
  172|       |	/* Set root path of this application */
  173|    521|	sc_file_free(p15card->file_app);
  174|    521|	p15card->file_app = sc_file_new();
  175|    521|	if (NULL == p15card->file_app) {
  ------------------
  |  Branch (175:6): [True: 0, False: 521]
  ------------------
  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|    521|	sc_format_path("3F00", &p15card->file_app->path);
  180|       |
  181|       |	/* Load TokenInfo */
  182|    521|	rv = dump_ef(p15card->card, "3F0050155032", buf, &len);
  183|    521|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of EF.TOKENINFO failed.");
  ------------------
  |  |  184|    521|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    521|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    521|	int _ret = (r); \
  |  |  |  |  178|    521|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 489, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  179|    489|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    489|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    489|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    489|		goto err; \
  |  |  |  |  182|    489|	} \
  |  |  |  |  183|    521|} 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|    521|err:
  270|    521|	sc_pkcs15_card_clear(p15card);
  271|    521|	p15card->opts.use_pin_cache = use_pin_cache_backup;
  272|    521|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|    521|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 521, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  273|    521|}
pkcs15-dnie.c:dump_ef:
   42|    521|{
   43|    521|	int rv;
   44|    521|	sc_file_t *file = NULL;
   45|    521|	sc_path_t scpath;
   46|    521|	sc_format_path(path, &scpath);
   47|    521|	rv = sc_select_file(card, &scpath, &file);
   48|    521|	if (rv < 0) {
  ------------------
  |  Branch (48:6): [True: 451, False: 70]
  ------------------
   49|    451|		sc_file_free(file);
   50|    451|		return rv;
   51|    451|	}
   52|     70|	if (file->size > *buf_len) {
  ------------------
  |  Branch (52:6): [True: 33, False: 37]
  ------------------
   53|     33|		sc_file_free(file);
   54|     33|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     33|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   55|     33|	}
   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.53k|{
  126|  7.53k|	if (dtrust_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (126:6): [True: 7.53k, False: 0]
  ------------------
  127|  7.53k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.53k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  128|       |
  129|      0|	return sc_pkcs15emu_dtrust_init(p15card, aid);
  130|  7.53k|}
pkcs15-dtrust.c:dtrust_pkcs15emu_detect_card:
   82|  7.53k|{
   83|  7.53k|	if (p15card->card->type < SC_CARD_TYPE_DTRUST_V4_1_STD)
  ------------------
  |  Branch (83:6): [True: 7.35k, False: 176]
  ------------------
   84|  7.35k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.35k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   85|       |
   86|    176|	if (p15card->card->type > SC_CARD_TYPE_DTRUST_V5_4_MULTI)
  ------------------
  |  Branch (86:6): [True: 176, False: 0]
  ------------------
   87|    176|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    176|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   88|       |
   89|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
   90|    176|}

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

sc_pkcs15emu_entersafe_init_ex:
   79|  10.4k|{
   80|  10.4k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.4k]
  |  |  ------------------
  ------------------
   81|       |
   82|  10.4k|	if (entersafe_detect_card(p15card))
  ------------------
  |  Branch (82:6): [True: 10.2k, False: 168]
  ------------------
   83|  10.2k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.2k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   84|    168|	return sc_pkcs15emu_entersafe_init(p15card);
   85|  10.4k|}
pkcs15-esinit.c:entersafe_detect_card:
   33|  10.4k|{
   34|  10.4k|	sc_card_t *card = p15card->card;
   35|       |
   36|  10.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.4k]
  |  |  ------------------
  ------------------
   37|       |
   38|       |	/* check if we have the correct card OS */
   39|  10.4k|	if (strcmp(card->name, "entersafe"))
  ------------------
  |  Branch (39:6): [True: 10.2k, False: 168]
  ------------------
   40|  10.2k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.2k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   41|       |
   42|    168|    return SC_SUCCESS;
  ------------------
  |  |   28|    168|#define SC_SUCCESS				0
  ------------------
   43|  10.4k|}
pkcs15-esinit.c:sc_pkcs15emu_entersafe_init:
   46|    168|{
   47|    168|	int    r;
   48|    168|	char   buf[256];
   49|    168|	sc_card_t *card = p15card->card;
   50|    168|	sc_serial_number_t serial;
   51|       |
   52|    168|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    168|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    168|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    168|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 168]
  |  |  ------------------
  ------------------
   53|       |
   54|       |	/* get serial number */
   55|    168|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
   56|    168|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    168|#define SC_SUCCESS				0
  ------------------
  |  Branch (56:6): [True: 165, False: 3]
  ------------------
   57|    165|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    165|#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.78k|int sc_pkcs15emu_esteid2018_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid) {
  257|  7.78k|	if (p15card->card->type == SC_CARD_TYPE_ESTEID_2018 ||
  ------------------
  |  Branch (257:6): [True: 55, False: 7.72k]
  ------------------
  258|  7.72k|			p15card->card->type == SC_CARD_TYPE_ESTEID_2018_V2_2025 ||
  ------------------
  |  Branch (258:4): [True: 0, False: 7.72k]
  ------------------
  259|  7.72k|			is_latvian_eid(p15card))
  ------------------
  |  Branch (259:4): [True: 0, False: 7.72k]
  ------------------
  260|     55|		return sc_pkcs15emu_esteid2018_init(p15card);
  261|  7.72k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.72k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  262|  7.78k|}
pkcs15-esteid2018.c:is_latvian_eid:
   38|  7.73k|{
   39|  7.73k|	return p15card->card->type == SC_CARD_TYPE_LATEID_2018 ||
  ------------------
  |  Branch (39:9): [True: 0, False: 7.73k]
  ------------------
   40|  7.73k|	       p15card->card->type == SC_CARD_TYPE_LATEID_2018_V2_2025;
  ------------------
  |  Branch (40:9): [True: 0, False: 7.73k]
  ------------------
   41|  7.73k|}
pkcs15-esteid2018.c:sc_pkcs15emu_esteid2018_init:
   43|     55|static int sc_pkcs15emu_esteid2018_init(sc_pkcs15_card_t *p15card) {
   44|     55|	sc_card_t *card = p15card->card;
   45|     55|	u8 buff[11];
   46|     55|	int r, i, cert_slot = 0;
   47|     55|	size_t field_length = 0, taglen, buflen;
   48|     55|	sc_path_t tmppath;
   49|       |
   50|       |	/* Read documber number to be used as serial */
   51|     55|	sc_format_path("3F00D003", &tmppath);
   52|     55|	LOG_TEST_RET(card->ctx, sc_select_file(card, &tmppath, NULL), "SELECT docnr");
  ------------------
  |  |  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: 39, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  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|     55|} 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: 2, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   55|     14|	const u8 *tag = sc_asn1_find_tag(card->ctx, buff, (size_t)r, 0x04, &taglen);
   56|     14|	if (tag == NULL)
  ------------------
  |  Branch (56:6): [True: 2, False: 12]
  ------------------
   57|     14|		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|     60|	for (size_t j = 0; j < taglen; j++)
  ------------------
  |  Branch (59:21): [True: 50, False: 10]
  ------------------
   60|     50|		if (!isalnum(tag[j]))
  ------------------
  |  Branch (60:7): [True: 2, False: 48]
  ------------------
   61|     12|			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|     14|#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|     10|	free(p15card->tokeninfo->serial_number);
   63|     10|	p15card->tokeninfo->serial_number = malloc(taglen + 1);
   64|     10|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (64:6): [True: 0, False: 10]
  ------------------
   65|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   66|       |
   67|     10|	set_string(&p15card->tokeninfo->label, "ID-kaart");
   68|     10|	set_string(&p15card->tokeninfo->manufacturer_id, "IDEMIA");
   69|     10|	p15card->tokeninfo->serial_number = memcpy(p15card->tokeninfo->serial_number, tag, taglen);
   70|     10|	p15card->tokeninfo->serial_number[taglen] = '\0';
   71|     10|	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|     10|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
   72|       |
   73|     10|	if (is_latvian_eid(p15card)) {
  ------------------
  |  Branch (73:6): [True: 0, False: 10]
  ------------------
   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|     10|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (111:14): [True: 10, False: 0]
  ------------------
  112|     10|		static const char *esteid_cert_names[2] = {"Isikutuvastus", "Allkirjastamine"};
  113|     10|		static const char *cert_paths[2][2] = {
  114|     10|				{"3f00:adf1:3401", "3f00:adf2:341f"},
  115|     10|				{"3f00:adf1:3402", "3f00:adf2:341e"}
  116|     10|		    };
  117|     10|		static const u8 esteid_cert_ids[2] = {1, 2};
  118|       |
  119|     10|		struct sc_pkcs15_cert_info cert_info = {
  120|     10|				.id = {.len = 1, .value[0] = esteid_cert_ids[i]}
  121|     10|		};
  122|     10|		struct sc_pkcs15_object cert_obj = {0};
  123|       |
  124|     10|		strlcpy(cert_obj.label, esteid_cert_names[i], sizeof(cert_obj.label));
  ------------------
  |  |   43|     10|#define strlcpy _strlcpy
  ------------------
  125|     10|		sc_format_path(cert_paths[cert_slot][i], &cert_info.path);
  126|     10|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  127|     10|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not add cert oebjct");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|       |
  129|       |		// Read data from first cert
  130|     10|		if (i != 0)
  ------------------
  |  Branch (130:7): [True: 0, False: 10]
  ------------------
  131|      0|			continue;
  132|       |
  133|     10|		sc_pkcs15_cert_t *cert = NULL;
  134|     10|		r = sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert);
  135|     10|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not read authentication certificate");
  ------------------
  |  |  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: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     10|} 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|     10|err:
  252|     10|	sc_pkcs15_card_clear(p15card);
  253|     10|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|     10|}

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

sc_pkcs15emu_gemsafeV1_init_ex:
  453|  10.4k|{
  454|  10.4k|	if (gemsafe_detect_card(p15card))
  ------------------
  |  Branch (454:6): [True: 9.57k, False: 841]
  ------------------
  455|  9.57k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.57k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  456|    841|	return sc_pkcs15emu_gemsafeV1_init(p15card);
  457|  10.4k|}
pkcs15-gemsafeV1.c:gemsafe_detect_card:
  300|  10.4k|{
  301|  10.4k|	if (strcmp(p15card->card->name, "GemSAFE V1"))
  ------------------
  |  Branch (301:6): [True: 9.57k, False: 841]
  ------------------
  302|  9.57k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.57k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  303|       |
  304|    841|	return SC_SUCCESS;
  ------------------
  |  |   28|    841|#define SC_SUCCESS				0
  ------------------
  305|  10.4k|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_gemsafeV1_init:
  308|    841|{
  309|    841|	int		    r;
  310|    841|	unsigned int    i;
  311|    841|	struct sc_path  path;
  312|    841|	struct sc_file *file = NULL;
  313|    841|	struct sc_card *card = p15card->card;
  314|    841|	struct sc_apdu  apdu;
  315|    841|	u8		    rbuf[SC_MAX_APDU_BUFFER_SIZE];
  316|       |
  317|    841|	sc_log(p15card->card->ctx, "Setting pkcs15 parameters");
  ------------------
  |  |   71|    841|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  318|       |
  319|    841|	set_string(&p15card->tokeninfo->label, APPLET_NAME);
  ------------------
  |  |   32|    841|#define APPLET_NAME		"GemSAFE V1"
  ------------------
  320|    841|	if (!p15card->tokeninfo->label)
  ------------------
  |  Branch (320:6): [True: 0, False: 841]
  ------------------
  321|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  322|       |
  323|    841|	set_string(&p15card->tokeninfo->serial_number, DRIVER_SERIAL_NUMBER);
  ------------------
  |  |   33|    841|#define DRIVER_SERIAL_NUMBER	"v0.9"
  ------------------
  324|    841|	if (!p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (324:6): [True: 0, False: 841]
  ------------------
  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|    841|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0xdf, 0x03);
  ------------------
  |  |  292|    841|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  332|    841|	apdu.cla = 0x80;
  333|    841|	apdu.resp = rbuf;
  334|    841|	apdu.resplen = sizeof(rbuf);
  335|       |	/* Manual says Le=0x05, but should be 0x08 to return full version number */
  336|    841|	apdu.le = 0x08;
  337|    841|	apdu.lc = 0;
  338|    841|	apdu.datalen = 0;
  339|    841|	r = sc_transmit_apdu(card, &apdu);
  340|    841|	if (r < 0)
  ------------------
  |  Branch (340:6): [True: 10, False: 831]
  ------------------
  341|     10|		sc_pkcs15_card_clear(p15card);
  342|    841|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    841|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    841|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    841|	int _ret = (r); \
  |  |  |  |  168|    841|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 831]
  |  |  |  |  ------------------
  |  |  |  |  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|    841|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 831]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  343|       |
  344|    831|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00 || r != SC_SUCCESS) {
  ------------------
  |  |   28|    141|#define SC_SUCCESS				0
  ------------------
  |  Branch (344:6): [True: 681, False: 150]
  |  Branch (344:26): [True: 9, False: 141]
  |  Branch (344:46): [True: 0, False: 141]
  ------------------
  345|    690|		sc_pkcs15_card_clear(p15card);
  346|    690|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    690|#define SC_ERROR_INTERNAL			-1400
  ------------------
  347|    690|	}
  348|       |
  349|       |	/* the manufacturer ID, in this case GemPlus */
  350|    141|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   31|    141|#define MANU_ID			"Gemplus"
  ------------------
  351|    141|	if (!p15card->tokeninfo->manufacturer_id) {
  ------------------
  |  Branch (351:6): [True: 0, False: 141]
  ------------------
  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|    141|	r = gemsafe_get_cert_len(card);
  358|    141|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    141|#define SC_SUCCESS				0
  ------------------
  |  Branch (358:6): [True: 93, False: 48]
  ------------------
  359|     93|		sc_pkcs15_card_clear(p15card);
  360|     93|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     93|#define SC_ERROR_INTERNAL			-1400
  ------------------
  361|     93|	}
  362|       |
  363|       |	/* set certs */
  364|     48|	sc_log(p15card->card->ctx, "Setting certificates");
  ------------------
  |  |   71|     48|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  365|    624|	for (i = 0; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (365:14): [True: 576, False: 48]
  ------------------
  366|    576|		struct sc_pkcs15_id p15Id;
  367|    576|		struct sc_path path;
  368|       |
  369|    576|		if (gemsafe_cert[i].label == NULL)
  ------------------
  |  Branch (369:7): [True: 576, False: 0]
  ------------------
  370|    576|			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|     48|	sc_log(p15card->card->ctx, "Setting PIN");
  ------------------
  |  |   71|     48|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  382|     95|	for (i=0; i < gemsafe_pin_max; i++) {
  ------------------
  |  Branch (382:12): [True: 95, False: 0]
  ------------------
  383|     95|		struct sc_pkcs15_id	p15Id;
  384|     95|		struct sc_path path;
  385|       |
  386|     95|		sc_pkcs15_format_id(gemsafe_pin[i].id, &p15Id);
  387|     95|		sc_format_path(gemsafe_pin[i].path, &path);
  388|     95|		if (gemsafe_pin[i].atr_len == 0 ||
  ------------------
  |  Branch (388:7): [True: 47, False: 48]
  ------------------
  389|     48|		   (gemsafe_pin[i].atr_len == p15card->card->atr.len &&
  ------------------
  |  Branch (389:7): [True: 6, False: 42]
  ------------------
  390|      6|		    memcmp(p15card->card->atr.value, gemsafe_pin[i].atr,
  ------------------
  |  Branch (390:7): [True: 1, False: 5]
  ------------------
  391|     48|			   p15card->card->atr.len) == 0)) {
  392|     48|			sc_pkcs15emu_add_pin(p15card, &p15Id, gemsafe_pin[i].label,
  393|     48|					     &path, gemsafe_pin[i].ref, gemsafe_pin[i].type,
  394|     48|					     gemsafe_pin[i].minlen, gemsafe_pin[i].maxlen,
  395|     48|					     gemsafe_pin[i].flags, gemsafe_pin[i].tries_left,
  396|     48|					     gemsafe_pin[i].pad_char, gemsafe_pin[i].obj_flags);
  397|     48|			break;
  398|     48|		}
  399|     95|	};
  400|       |
  401|       |	/* set private keys */
  402|     48|	sc_log(p15card->card->ctx, "Setting private keys");
  ------------------
  |  |   71|     48|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  403|    624|	for (i = 0; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (403:14): [True: 576, False: 48]
  ------------------
  404|    576|		struct sc_pkcs15_id p15Id, authId, *pauthId;
  405|    576|		struct sc_path path;
  406|    576|		int key_ref = 0x03;
  407|       |
  408|    576|		if (gemsafe_prkeys[i].label == NULL)
  ------------------
  |  Branch (408:7): [True: 576, False: 0]
  ------------------
  409|    576|			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|     48|	sc_log(p15card->card->ctx, "Selecting application DF");
  ------------------
  |  |   71|     48|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  438|     48|	sc_format_path(GEMSAFE_APP_PATH, &path);
  ------------------
  |  |   34|     48|#define GEMSAFE_APP_PATH	"3F001600"
  ------------------
  439|     48|	r = sc_select_file(card, &path, &file);
  440|     48|	if (r != SC_SUCCESS || !file) {
  ------------------
  |  |   28|     96|#define SC_SUCCESS				0
  ------------------
  |  Branch (440:6): [True: 36, False: 12]
  |  Branch (440:25): [True: 0, False: 12]
  ------------------
  441|     36|		sc_pkcs15_card_clear(p15card);
  442|     36|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     36|#define SC_ERROR_INTERNAL			-1400
  ------------------
  443|     36|	}
  444|       |	/* set the application DF */
  445|     12|	sc_file_free(p15card->file_app);
  446|     12|	p15card->file_app = file;
  447|       |
  448|     12|	return SC_SUCCESS;
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
  449|     48|}
pkcs15-gemsafeV1.c:gemsafe_get_cert_len:
  163|    141|{
  164|    141|	int r;
  165|    141|	u8  ibuf[GEMSAFE_MAX_OBJLEN];
  166|    141|	u8 *iptr;
  167|    141|	struct sc_path path;
  168|    141|	struct sc_file *file;
  169|    141|	size_t objlen;
  170|    141|	int certlen;
  171|    141|	unsigned int ind, i=0;
  172|    141|	int read_len;
  173|       |
  174|    141|	sc_format_path(GEMSAFE_PATH, &path);
  ------------------
  |  |   35|    141|#define GEMSAFE_PATH		"3F0016000004"
  ------------------
  175|    141|	r = sc_select_file(card, &path, &file);
  176|    141|	if (r != SC_SUCCESS || !file)
  ------------------
  |  |   28|    282|#define SC_SUCCESS				0
  ------------------
  |  Branch (176:6): [True: 6, False: 135]
  |  Branch (176:25): [True: 0, False: 135]
  ------------------
  177|      6|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      6|#define SC_ERROR_INTERNAL			-1400
  ------------------
  178|    135|	sc_file_free(file);
  179|       |
  180|       |	/* Initial read */
  181|    135|	read_len = sc_read_binary(card, 0, ibuf, GEMSAFE_READ_QUANTUM, 0);
  ------------------
  |  |   40|    135|#define GEMSAFE_READ_QUANTUM    248
  ------------------
  182|    135|	if (read_len <= 2) {
  ------------------
  |  Branch (182:6): [True: 8, False: 127]
  ------------------
  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|    127|	objlen = (((size_t) ibuf[0]) << 8) | ibuf[1];
  191|    127|	sc_log(card->ctx, "Stored object is of size: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  192|    127|	       objlen);
  193|    127|	if (objlen < 1 || objlen > GEMSAFE_MAX_OBJLEN) {
  ------------------
  |  |   41|    126|#define GEMSAFE_MAX_OBJLEN      28672
  ------------------
  |  Branch (193:6): [True: 1, False: 126]
  |  Branch (193:20): [True: 12, False: 114]
  ------------------
  194|     13|	    sc_log(card->ctx, "Invalid object size: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  195|     13|		   objlen);
  196|     13|	    return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     13|#define SC_ERROR_INTERNAL			-1400
  ------------------
  197|     13|	}
  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|    114|	ind = 2; /* skip length */
  214|    217|	while (ind + 1 < (size_t)read_len && ibuf[ind] == 0x01 && i < gemsafe_cert_max) {
  ------------------
  |  Branch (214:9): [True: 187, False: 30]
  |  Branch (214:39): [True: 103, False: 84]
  |  Branch (214:60): [True: 103, False: 0]
  ------------------
  215|    103|		if (ibuf[ind+1] == 0xFE) {
  ------------------
  |  Branch (215:7): [True: 32, False: 71]
  ------------------
  216|     32|			gemsafe_prkeys[i].ref = ibuf[ind+4];
  217|     32|			sc_log(card->ctx, "Key container %d is allocated and uses key_ref %d",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  218|     32|					i+1, gemsafe_prkeys[i].ref);
  219|     32|			ind += 9;
  220|     32|		}
  221|     71|		else {
  222|     71|			gemsafe_prkeys[i].label = NULL;
  223|     71|			gemsafe_cert[i].label = NULL;
  224|     71|			sc_log(card->ctx, "Key container %d is unallocated", i+1);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  225|     71|			ind += 8;
  226|     71|		}
  227|    103|		i++;
  228|    103|	}
  229|       |
  230|       |	/* Delete additional key containers from the data structures if
  231|       |	 * this card can't accommodate them.
  232|       |	 */
  233|  1.37k|	for (; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (233:9): [True: 1.26k, False: 114]
  ------------------
  234|  1.26k|		gemsafe_prkeys[i].label = NULL;
  235|  1.26k|		gemsafe_cert[i].label = NULL;
  236|  1.26k|	}
  237|       |
  238|       |	/* Read entire file, then dissect in memory.
  239|       |	 * Gemalto ClassicClient seems to do it the same way.
  240|       |	 */
  241|    114|	iptr = ibuf + read_len;
  242|  1.91k|	while ((size_t)(iptr - ibuf) < objlen) {
  ------------------
  |  Branch (242:9): [True: 1.86k, False: 48]
  ------------------
  243|  1.86k|		r = sc_read_binary(card, (unsigned)(iptr - ibuf), iptr,
  244|  1.86k|				   MIN(GEMSAFE_READ_QUANTUM, objlen - (iptr - ibuf)), 0);
  ------------------
  |  |   70|  1.86k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 1.76k, False: 99]
  |  |  ------------------
  ------------------
  245|  1.86k|		if (r < 0) {
  ------------------
  |  Branch (245:7): [True: 58, False: 1.80k]
  ------------------
  246|     58|			sc_log(card->ctx, "Could not read cert object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  247|     58|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     58|#define SC_ERROR_INTERNAL			-1400
  ------------------
  248|     58|		}
  249|  1.80k|		if (r == 0)
  ------------------
  |  Branch (249:7): [True: 8, False: 1.79k]
  ------------------
  250|      8|			break;
  251|  1.79k|		read_len += r;
  252|  1.79k|		iptr += r;
  253|  1.79k|	}
  254|     56|	if ((size_t)read_len < objlen) {
  ------------------
  |  Branch (254:6): [True: 8, False: 48]
  ------------------
  255|      8|		sc_log(card->ctx, "Could not read cert object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  256|      8|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      8|#define SC_ERROR_INTERNAL			-1400
  ------------------
  257|      8|	}
  258|       |
  259|       |	/* Search buffer for certificates, they start with 0x3082. */
  260|     48|	i = 0;
  261|    568|	while (ind < objlen - 1) {
  ------------------
  |  Branch (261:9): [True: 521, False: 47]
  ------------------
  262|    521|		if (ibuf[ind] == 0x30 && ibuf[ind+1] == 0x82) {
  ------------------
  |  Branch (262:7): [True: 201, False: 320]
  |  Branch (262:28): [True: 1, False: 200]
  ------------------
  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|    520|			ind++;
  283|    521|	}
  284|       |
  285|       |	/* Delete additional key containers from the data structures if
  286|       |	 * they're missing on the card.
  287|       |	 */
  288|    611|	for (; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (288:9): [True: 564, False: 47]
  ------------------
  289|    564|		if (gemsafe_cert[i].label) {
  ------------------
  |  Branch (289:7): [True: 0, False: 564]
  ------------------
  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|    564|	}
  295|       |
  296|     47|	return SC_SUCCESS;
  ------------------
  |  |   28|     47|#define SC_SUCCESS				0
  ------------------
  297|     48|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_add_object:
  492|     48|{
  493|     48|	sc_pkcs15_object_t *obj;
  494|     48|	int		df_type;
  495|       |
  496|     48|	obj = calloc(1, sizeof(*obj));
  497|     48|	if (!obj) {
  ------------------
  |  Branch (497:6): [True: 0, False: 48]
  ------------------
  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|     48|	obj->type  = type;
  502|     48|	obj->data  = data;
  503|       |
  504|     48|	if (label)
  ------------------
  |  Branch (504:6): [True: 48, False: 0]
  ------------------
  505|     48|		strncpy(obj->label, label, sizeof(obj->label)-1);
  506|       |
  507|     48|	obj->flags = obj_flags;
  508|     48|	if (auth_id)
  ------------------
  |  Branch (508:6): [True: 0, False: 48]
  ------------------
  509|      0|		obj->auth_id = *auth_id;
  510|       |
  511|     48|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|     48|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  512|     48|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|     48|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (512:2): [True: 48, False: 0]
  ------------------
  513|     48|		df_type = SC_PKCS15_AODF;
  ------------------
  |  |  496|     48|#define SC_PKCS15_AODF			8
  ------------------
  514|     48|		break;
  515|      0|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (515:2): [True: 0, False: 48]
  ------------------
  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: 48]
  ------------------
  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: 48]
  ------------------
  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: 48]
  ------------------
  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|     48|	}
  529|       |
  530|     48|	obj->df = sc_pkcs15emu_get_df(p15card, df_type);
  531|     48|	sc_pkcs15_add_object(p15card, obj);
  532|       |
  533|     48|	return 0;
  534|     48|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_get_df:
  461|     48|{
  462|     48|	sc_pkcs15_df_t	*df;
  463|     48|	sc_file_t	*file;
  464|     48|	int		created = 0;
  465|       |
  466|     96|	while (1) {
  ------------------
  |  Branch (466:9): [True: 96, Folded]
  ------------------
  467|     96|		for (df = p15card->df_list; df; df = df->next) {
  ------------------
  |  Branch (467:31): [True: 48, False: 48]
  ------------------
  468|     48|			if (df->type == type) {
  ------------------
  |  Branch (468:8): [True: 48, False: 0]
  ------------------
  469|     48|				if (created)
  ------------------
  |  Branch (469:9): [True: 48, False: 0]
  ------------------
  470|     48|					df->enumerated = 1;
  471|     48|				return df;
  472|     48|			}
  473|     48|		}
  474|       |
  475|     48|		if (created != 0)
  ------------------
  |  Branch (475:7): [True: 0, False: 48]
  ------------------
  476|      0|			return NULL;
  477|       |
  478|     48|		file = sc_file_new();
  479|     48|		if (!file)
  ------------------
  |  Branch (479:7): [True: 0, False: 48]
  ------------------
  480|      0|			return NULL;
  481|     48|		sc_format_path("11001101", &file->path);
  482|     48|		sc_pkcs15_add_df(p15card, type, &file->path);
  483|     48|		sc_file_free(file);
  484|     48|		created++;
  485|     48|	}
  486|     48|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_add_pin:
  543|     48|{
  544|     48|	sc_pkcs15_auth_info_t *info;
  545|       |
  546|     48|	info = calloc(1, sizeof(*info));
  547|     48|	if (!info)
  ------------------
  |  Branch (547:6): [True: 0, False: 48]
  ------------------
  548|     48|		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|     48|	info->auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     48|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  551|     48|	info->auth_method = SC_AC_CHV;
  ------------------
  |  |  151|     48|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  552|     48|	info->auth_id           = *id;
  553|     48|	info->attrs.pin.min_length        = min_length;
  554|     48|	info->attrs.pin.max_length        = max_length;
  555|     48|	info->attrs.pin.stored_length     = max_length;
  556|     48|	info->attrs.pin.type              = type;
  557|     48|	info->attrs.pin.reference         = ref;
  558|     48|	info->attrs.pin.flags             = flags;
  559|     48|	info->attrs.pin.pad_char          = pad_char;
  560|     48|	info->tries_left        = tries_left;
  561|     48|	info->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|     48|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  562|       |
  563|     48|	if (path)
  ------------------
  |  Branch (563:6): [True: 48, False: 0]
  ------------------
  564|     48|		info->path = *path;
  565|       |
  566|     48|	return sc_pkcs15emu_add_object(p15card, SC_PKCS15_TYPE_AUTH_PIN, label, info, NULL, obj_flags);
  ------------------
  |  |  445|     48|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  567|     48|}

sc_pkcs15emu_gids_init_ex:
  243|  10.0k|{
  244|  10.0k|	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.96k, False: 129]
  |  Branch (244:58): [True: 9.96k, False: 1]
  |  Branch (244:105): [True: 9.96k, False: 1]
  ------------------
  245|  9.96k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.96k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  246|  9.96k|	}
  247|    131|	return sc_pkcs15emu_gids_init(p15card);
  248|  10.0k|}
pkcs15-gids.c:sc_pkcs15emu_gids_init:
  114|    131|{
  115|    131|	sc_card_t *card = p15card->card;
  116|    131|	int r;
  117|    131|	size_t i;
  118|    131|	struct sc_pkcs15_auth_info pin_info;
  119|    131|	struct sc_pkcs15_object pin_obj;
  120|    131|	struct sc_pin_cmd_data pin_cmd_data;
  121|    131|	size_t recordsnum;
  122|    131|	int has_puk;
  123|       |
  124|    131|	r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
  125|    131|	LOG_TEST_RET(card->ctx, r, "unable to get the containers. Uninitialized card ?");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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);
  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) == 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:
  268|  10.0k|{
  269|  10.0k|	if (iasecc_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (269:6): [True: 9.50k, False: 597]
  ------------------
  270|  9.50k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.50k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  271|       |
  272|    597|	return sc_pkcs15emu_iasecc_init(p15card, aid);
  273|  10.0k|}
pkcs15-iasecc.c:iasecc_pkcs15emu_detect_card:
  239|  10.0k|{
  240|  10.0k|	if (p15card->card->type < SC_CARD_TYPE_IASECC_BASE)
  ------------------
  |  Branch (240:6): [True: 7.11k, False: 2.98k]
  ------------------
  241|  7.11k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.11k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  242|       |
  243|  2.98k|	if (p15card->card->type > SC_CARD_TYPE_IASECC_BASE + 10)
  ------------------
  |  Branch (243:6): [True: 2.38k, False: 597]
  ------------------
  244|  2.38k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  2.38k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  245|       |
  246|    597|	return SC_SUCCESS;
  ------------------
  |  |   28|    597|#define SC_SUCCESS				0
  ------------------
  247|  2.98k|}
pkcs15-iasecc.c:sc_pkcs15emu_iasecc_init:
  252|    597|{
  253|    597|	struct sc_context *ctx = p15card->card->ctx;
  254|    597|	int rv;
  255|       |
  256|    597|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    597|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    597|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    597|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    597|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 597]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|       |
  258|    597|	rv = sc_pkcs15_bind_internal(p15card, aid);
  259|       |
  260|    597|	p15card->ops.parse_df = _iasecc_parse_df;
  261|       |
  262|    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|    594|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 594, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  263|    597|}

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

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

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

sc_pkcs15emu_oberthur_init_ex:
 1163|  10.2k|{
 1164|  10.2k|	int rv;
 1165|       |
 1166|  10.2k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  10.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  10.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  10.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  10.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1167|  10.2k|	rv = oberthur_detect_card(p15card);
 1168|  10.2k|	if (!rv)
  ------------------
  |  Branch (1168:6): [True: 839, False: 9.39k]
  ------------------
 1169|    839|		rv = sc_pkcs15emu_oberthur_init(p15card);
 1170|       |
 1171|  10.2k|	LOG_FUNC_RETURN(p15card->card->ctx, rv);
  ------------------
  |  |  164|  10.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.2k|	int _ret = r; \
  |  |  |  |  155|  10.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  10.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10.0k, False: 136]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.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|  10.2k|	return _ret; \
  |  |  |  |  163|  10.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1172|  10.2k|}
pkcs15-oberthur.c:oberthur_detect_card:
 1151|  10.2k|{
 1152|  10.2k|	struct sc_card *card = p15card->card;
 1153|       |
 1154|  10.2k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  10.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.2k]
  |  |  ------------------
  ------------------
 1155|  10.2k|	if (p15card->card->type != SC_CARD_TYPE_OBERTHUR_64K)
  ------------------
  |  Branch (1155:6): [True: 9.39k, False: 839]
  ------------------
 1156|  10.2k|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  9.39k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.39k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.39k|	int _ret = r; \
  |  |  |  |  155|  9.39k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.39k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.39k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  9.39k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.39k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.39k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.39k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  9.39k|	return _ret; \
  |  |  |  |  163|  9.39k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1157|    839|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    839|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    839|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    839|	int _ret = r; \
  |  |  |  |  155|    839|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 839, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    839|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 839]
  |  |  |  |  ------------------
  |  |  |  |  157|    839|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    839|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    839|	return _ret; \
  |  |  |  |  163|    839|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1158|    839|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_init:
 1017|    839|{
 1018|    839|	struct sc_context *ctx = p15card->card->ctx;
 1019|    839|	struct sc_pkcs15_auth_info auth_info;
 1020|    839|	struct sc_pkcs15_object   obj;
 1021|    839|	struct sc_card *card = p15card->card;
 1022|    839|	struct sc_path path;
 1023|    839|	int rv, ii, tries_left;
 1024|    839|	char serial[0x10];
 1025|    839|	unsigned char sopin_reference = 0x04;
 1026|       |
 1027|    839|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    839|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    839|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    839|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 839]
  |  |  ------------------
  ------------------
 1028|    839|	sc_bin_to_hex(card->serialnr.value, card->serialnr.len, serial, sizeof(serial), 0);
 1029|    839|	set_string(&p15card->tokeninfo->serial_number, serial);
 1030|       |
 1031|    839|	p15card->ops.parse_df = sc_awp_parse_df;
 1032|    839|	p15card->ops.clear = sc_awp_clear;
 1033|       |
 1034|    839|	sc_log(ctx, "Oberthur init: serial %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   71|    839|#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|    839|	sc_format_path(AWP_PIN_DF, &path);
  ------------------
  |  |   69|    839|#define AWP_PIN_DF		"3F005011"
  ------------------
 1037|    839|	rv = sc_select_file(card, &path, NULL);
 1038|    839|	LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot select PIN dir");
  ------------------
  |  |  184|    839|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    839|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    839|	int _ret = (r); \
  |  |  |  |  178|    839|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 303, False: 536]
  |  |  |  |  ------------------
  |  |  |  |  179|    303|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    303|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    303|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    303|		goto err; \
  |  |  |  |  182|    303|	} \
  |  |  |  |  183|    839|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 536]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1039|       |
 1040|    536|	tries_left = -1;
 1041|    536|	rv = sc_verify(card, SC_AC_CHV, sopin_reference, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|    536|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1042|    536|	if (rv && rv != SC_ERROR_PIN_CODE_INCORRECT)   {
  ------------------
  |  |   64|     37|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1042:6): [True: 37, False: 499]
  |  Branch (1042:12): [True: 34, False: 3]
  ------------------
 1043|     34|		sopin_reference = 0x84;
 1044|     34|		rv = sc_verify(card, SC_AC_CHV, sopin_reference, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|     34|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1045|     34|	}
 1046|    536|	if (rv && rv != SC_ERROR_PIN_CODE_INCORRECT)
  ------------------
  |  |   64|     30|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1046:6): [True: 30, False: 506]
  |  Branch (1046:12): [True: 25, False: 5]
  ------------------
 1047|    536|		LOG_TEST_GOTO_ERR(ctx, rv, "Invalid state of SO-PIN");
  ------------------
  |  |  184|     25|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     25|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     25|	int _ret = (r); \
  |  |  |  |  178|     25|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     25|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     25|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     25|		goto err; \
  |  |  |  |  182|     25|	} \
  |  |  |  |  183|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1048|       |
 1049|       |	/* add PIN */
 1050|    511|	memset(&auth_info, 0, sizeof(auth_info));
 1051|    511|	memset(&obj,  0, sizeof(obj));
 1052|       |
 1053|    511|	auth_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    511|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
 1054|    511|	auth_info.auth_method	= SC_AC_CHV;
  ------------------
  |  |  151|    511|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1055|    511|	auth_info.auth_id.len = 1;
 1056|    511|	auth_info.auth_id.value[0] = 0xFF;
 1057|    511|	auth_info.attrs.pin.min_length		= 4;
 1058|    511|	auth_info.attrs.pin.max_length		= 64;
 1059|    511|	auth_info.attrs.pin.stored_length	= 64;
 1060|    511|	auth_info.attrs.pin.type		= SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    511|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
 1061|    511|	auth_info.attrs.pin.reference		= sopin_reference;
 1062|    511|	auth_info.attrs.pin.pad_char		= 0xFF;
 1063|    511|	auth_info.attrs.pin.flags		= SC_PKCS15_PIN_FLAG_CASE_SENSITIVE
  ------------------
  |  |   54|    511|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  ------------------
 1064|    511|				| SC_PKCS15_PIN_FLAG_INITIALIZED
  ------------------
  |  |   58|    511|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
 1065|    511|				| SC_PKCS15_PIN_FLAG_NEEDS_PADDING
  ------------------
  |  |   59|    511|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
 1066|    511|				| SC_PKCS15_PIN_FLAG_SO_PIN;
  ------------------
  |  |   61|    511|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
 1067|    511|	auth_info.tries_left		= tries_left;
 1068|    511|	auth_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|    511|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1069|       |
 1070|    511|	strncpy(obj.label, "SO PIN", SC_PKCS15_MAX_LABEL_SIZE-1);
  ------------------
  |  |   35|    511|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1071|    511|	obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|    511|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              	obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    511|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1072|       |
 1073|    511|	sc_log(ctx, "Add PIN(%s,auth_id:%s,reference:%i)", obj.label,
  ------------------
  |  |   71|    511|#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|    511|			sc_pkcs15_print_id(&auth_info.auth_id), auth_info.attrs.pin.reference);
 1075|    511|	rv = sc_pkcs15emu_add_pin_obj(p15card, &obj, &auth_info);
 1076|    511|	LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot add PIN object");
  ------------------
  |  |  184|    511|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    511|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    511|	int _ret = (r); \
  |  |  |  |  178|    511|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 511]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    511|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 511]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1077|       |
 1078|    511|	tries_left = -1;
 1079|    511|	rv = sc_verify(card, SC_AC_CHV, 0x81, (unsigned char *)"", 0, &tries_left);
  ------------------
  |  |  151|    511|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1080|    511|	if (rv == SC_ERROR_PIN_CODE_INCORRECT)   {
  ------------------
  |  |   64|    511|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1080:6): [True: 3, False: 508]
  ------------------
 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|    508|	else if (rv != SC_ERROR_DATA_OBJECT_NOT_FOUND)    {
  ------------------
  |  |   66|    508|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (1122:11): [True: 507, False: 1]
  ------------------
 1123|    507|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: cannot verify PIN");
  ------------------
  |  |  184|    507|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    507|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    507|	int _ret = (r); \
  |  |  |  |  178|    507|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 13, False: 494]
  |  |  |  |  ------------------
  |  |  |  |  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|    507|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 494]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1124|    507|	}
 1125|       |
 1126|  1.76k|	for (ii=0; oberthur_infos[ii].name; ii++)   {
  ------------------
  |  Branch (1126:13): [True: 1.62k, False: 136]
  ------------------
 1127|  1.62k|		sc_log(ctx, "Oberthur init: read %s file", oberthur_infos[ii].name);
  ------------------
  |  |   71|  1.62k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1128|  1.62k|		free(oberthur_infos[ii].content);
 1129|  1.62k|		rv = sc_oberthur_read_file(p15card, oberthur_infos[ii].path,
 1130|  1.62k|				&oberthur_infos[ii].content, &oberthur_infos[ii].len, 1);
 1131|  1.62k|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: read oberthur file error");
  ------------------
  |  |  184|  1.62k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.62k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.62k|	int _ret = (r); \
  |  |  |  |  178|  1.62k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 90, False: 1.53k]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     90|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     90|		goto err; \
  |  |  |  |  182|     90|	} \
  |  |  |  |  183|  1.62k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.53k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1132|       |
 1133|  1.53k|		sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1134|  1.53k|		       "Oberthur init: parse %s file, content length %"SC_FORMAT_LEN_SIZE_T"u",
 1135|  1.53k|		       oberthur_infos[ii].name, oberthur_infos[ii].len);
 1136|  1.53k|		rv = oberthur_infos[ii].parser(p15card, oberthur_infos[ii].content, oberthur_infos[ii].len,
 1137|  1.53k|				oberthur_infos[ii].postpone_allowed);
 1138|  1.53k|		LOG_TEST_GOTO_ERR(ctx, rv, "Oberthur init failed: parse error");
  ------------------
  |  |  184|  1.53k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.53k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.53k|	int _ret = (r); \
  |  |  |  |  178|  1.53k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 272, False: 1.26k]
  |  |  |  |  ------------------
  |  |  |  |  179|    272|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    272|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    272|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    272|		goto err; \
  |  |  |  |  182|    272|	} \
  |  |  |  |  183|  1.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.26k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1139|  1.53k|	}
 1140|       |
 1141|    136|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    136|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    136|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    136|	int _ret = r; \
  |  |  |  |  155|    136|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 136, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    136|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 136]
  |  |  |  |  ------------------
  |  |  |  |  157|    136|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    136|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    136|	return _ret; \
  |  |  |  |  163|    136|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1142|       |
 1143|    703|err:
 1144|    703|	sc_pkcs15_card_clear(p15card);
 1145|    703|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|    703|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 703, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1146|    703|}
pkcs15-oberthur.c:sc_oberthur_parse_privateinfo:
  502|    244|{
  503|    244|	struct sc_context *ctx = p15card->card->ctx;
  504|    244|	size_t ii;
  505|    244|	int rv;
  506|    244|	int no_more_private_keys = 0, no_more_private_data = 0;
  507|       |
  508|    244|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    244|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    244|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    244|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    244|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 244]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  509|       |
  510|  43.7k|	for (ii=0; ii+5<=len; ii+=5)   {
  ------------------
  |  Branch (510:13): [True: 43.6k, False: 136]
  ------------------
  511|  43.6k|		unsigned int file_id, size;
  512|       |
  513|  43.6k|		if(*(buff+ii) != 0xFF)
  ------------------
  |  Branch (513:6): [True: 43.2k, False: 381]
  ------------------
  514|  43.2k|			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|    344|		case BASE_ID_PRV_RSA :
  ------------------
  |  |   83|    344|#define BASE_ID_PRV_RSA   0x30
  ------------------
  |  Branch (521:3): [True: 344, False: 37]
  ------------------
  522|    344|			if (no_more_private_keys)
  ------------------
  |  Branch (522:8): [True: 10, False: 334]
  ------------------
  523|     10|				break;
  524|       |
  525|    334|			rv = sc_pkcs15emu_oberthur_add_prvkey(p15card, file_id, size);
  526|    334|			if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed)   {
  ------------------
  |  |   61|    668|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (526:8): [True: 5, False: 329]
  |  Branch (526:56): [True: 5, False: 0]
  ------------------
  527|      5|				struct sc_path path;
  528|       |
  529|      5|				sc_log(ctx, "postpone adding of the private keys");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  530|      5|				sc_format_path("5011A5A5", &path);
  531|      5|				rv = sc_pkcs15_add_df(p15card, SC_PKCS15_PRKDF, &path);
  ------------------
  |  |  488|      5|#define SC_PKCS15_PRKDF			0
  ------------------
  532|      5|				LOG_TEST_RET(ctx, rv, "Add PrkDF error");
  ------------------
  |  |  174|      5|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      5|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      5|	int _ret = (r); \
  |  |  |  |  168|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  533|      5|				no_more_private_keys = 1;
  534|      5|			}
  535|    334|			LOG_TEST_RET(ctx, rv, "Cannot parse private key info");
  ------------------
  |  |  174|    334|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    334|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    334|	int _ret = (r); \
  |  |  |  |  168|    334|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 96, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  169|     96|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     96|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     96|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     96|		return _ret; \
  |  |  |  |  172|     96|	} \
  |  |  |  |  173|    334|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 238]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|    238|			break;
  537|    238|		case BASE_ID_PRV_DES :
  ------------------
  |  |   84|      6|#define BASE_ID_PRV_DES   0x40
  ------------------
  |  Branch (537:3): [True: 6, False: 375]
  ------------------
  538|      6|			break;
  539|     23|		case BASE_ID_PRV_DATA :
  ------------------
  |  |   86|     23|#define BASE_ID_PRV_DATA  0x60
  ------------------
  |  Branch (539:3): [True: 23, False: 358]
  ------------------
  540|     23|			sc_log(ctx, "*(buff+ii + 1):%X", *(buff+ii + 1));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  541|     23|			if (no_more_private_data)
  ------------------
  |  Branch (541:8): [True: 10, False: 13]
  ------------------
  542|     10|				break;
  543|       |
  544|     13|			rv = sc_pkcs15emu_oberthur_add_data(p15card, file_id, size, 1);
  545|     13|			if (rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED && postpone_allowed)   {
  ------------------
  |  |   61|     26|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (545:8): [True: 4, False: 9]
  |  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|     13|			LOG_TEST_RET(ctx, rv, "Cannot parse private data info");
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  555|      9|			break;
  556|      9|		default:
  ------------------
  |  Branch (556:3): [True: 8, False: 373]
  ------------------
  557|      8|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Private object parse error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  558|    381|		}
  559|    381|	}
  560|       |
  561|    136|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    136|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    136|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    136|	int _ret = r; \
  |  |  |  |  155|    136|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 136, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    136|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 136]
  |  |  |  |  ------------------
  |  |  |  |  157|    136|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    136|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    136|	return _ret; \
  |  |  |  |  163|    136|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  562|    136|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_prvkey:
  765|    334|{
  766|    334|	struct sc_context *ctx = p15card->card->ctx;
  767|    334|	struct sc_pkcs15_prkey_info kinfo;
  768|    334|	struct sc_pkcs15_object kobj;
  769|    334|	struct crypto_container ccont;
  770|    334|	unsigned char *info_blob = NULL;
  771|    334|	size_t info_len = 0;
  772|    334|	unsigned flags;
  773|    334|	size_t offs, len;
  774|    334|	char ch_tmp[0x100];
  775|    334|	int rv;
  776|       |
  777|    334|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    334|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    334|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    334|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    334|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 334]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|    334|	sc_log(ctx, "add private key(file-id:%04X,size:%04X)", file_id, size);
  ------------------
  |  |   71|    334|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  779|       |
  780|    334|	memset(&kinfo, 0, sizeof(kinfo));
  781|    334|	memset(&kobj, 0, sizeof(kobj));
  782|    334|	memset(&ccont, 0, sizeof(ccont));
  783|       |
  784|    334|	rv = sc_oberthur_get_friends (file_id, &ccont);
  785|    334|	LOG_TEST_RET(ctx, rv, "Failed to add private key: get friends error");
  ------------------
  |  |  174|    334|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    334|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    334|	int _ret = (r); \
  |  |  |  |  168|    334|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 38, False: 296]
  |  |  |  |  ------------------
  |  |  |  |  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|    334|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 296]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  786|       |
  787|    296|	if (ccont.id_cert)   {
  ------------------
  |  Branch (787:6): [True: 4, False: 292]
  ------------------
  788|      4|		struct sc_pkcs15_object *objs[32];
  789|      4|		int ii;
  790|       |
  791|      4|		sc_log(ctx, "friend certificate %04X", ccont.id_cert);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  792|      4|		rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_CERT_X509, objs, 32);
  ------------------
  |  |  439|      4|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  793|      4|		LOG_TEST_RET(ctx, rv, "Failed to add private key: get certificates 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  794|       |
  795|      4|		for (ii=0; ii<rv; ii++) {
  ------------------
  |  Branch (795:14): [True: 0, False: 4]
  ------------------
  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|      4|		if (ii == rv)
  ------------------
  |  Branch (806:7): [True: 4, False: 0]
  ------------------
  807|      4|			LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_PROFILE, "Failed to add private key: friend not found");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  808|      4|	}
  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: 19, False: 273]
  |  |  |  |  ------------------
  |  |  |  |  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|    292|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 273]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  813|       |
  814|    273|	if (info_len < 2) {
  ------------------
  |  Branch (814:6): [True: 5, False: 268]
  ------------------
  815|      5|		free(info_blob);
  816|      5|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add private key: no 'tag'");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  817|      5|	}
  818|    268|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  819|    268|	offs = 2;
  820|       |
  821|       |	/* CN */
  822|    268|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (822:6): [True: 1, False: 267]
  ------------------
  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|    267|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  827|    267|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (827:6): [True: 9, False: 258]
  ------------------
  828|      9|		free(info_blob);
  829|      9|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'CN' 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  830|      9|	}
  831|    258|	if (len && !strlen(kobj.label))   {
  ------------------
  |  Branch (831:6): [True: 43, False: 215]
  |  Branch (831:13): [True: 43, False: 0]
  ------------------
  832|     43|		if (len > sizeof(kobj.label) - 1)
  ------------------
  |  Branch (832:7): [True: 1, False: 42]
  ------------------
  833|      1|			len = sizeof(kobj.label) - 1;
  834|     43|		strncpy(kobj.label, (char *)(info_blob + offs + 2), len);
  835|     43|	}
  836|    258|	offs += 2 + len;
  837|       |
  838|       |	/* ID */
  839|    258|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (839:6): [True: 1, False: 257]
  ------------------
  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|    257|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  844|    257|	if (!len) {
  ------------------
  |  Branch (844:6): [True: 1, False: 256]
  ------------------
  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|    256|	} else if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (847:13): [True: 19, False: 237]
  ------------------
  848|     19|		free(info_blob);
  849|     19|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'ID' length");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     19|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     19|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     19|		return _ret; \
  |  |  |  |  172|     19|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  850|    237|	} else if (len > sizeof(kinfo.id.value)) {
  ------------------
  |  Branch (850:13): [True: 1, False: 236]
  ------------------
  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|    236|	memcpy(kinfo.id.value, info_blob + offs + 2, len);
  855|    236|	kinfo.id.len = len;
  856|    236|	offs += 2 + len;
  857|       |
  858|       |	/* Ignore Start/End dates */
  859|    236|	offs += 16;
  860|       |
  861|       |	/* Subject encoded in ASN1 */
  862|    236|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (862:6): [True: 1, False: 235]
  ------------------
  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|    235|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  867|    235|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (867:6): [True: 2, False: 233]
  ------------------
  868|      2|		free(info_blob);
  869|      2|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'subject' length");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  870|    233|	} else if (len) {
  ------------------
  |  Branch (870:13): [True: 225, False: 8]
  ------------------
  871|    225|		kinfo.subject.value = malloc(len);
  872|    225|		if (!kinfo.subject.value) {
  ------------------
  |  Branch (872:7): [True: 0, False: 225]
  ------------------
  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|    225|		kinfo.subject.len = len;
  877|    225|		memcpy(kinfo.subject.value, info_blob + offs + 2, len);
  878|    225|	}
  879|       |
  880|       |	/* Modulus and exponent are ignored */
  881|       |
  882|    233|	free(info_blob);
  883|       |
  884|    233|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PRV, file_id);
  ------------------
  |  |   76|    233|#define AWP_OBJECTS_DF_PRV	"3F0050119002"
  ------------------
  885|    233|	sc_format_path(ch_tmp, &kinfo.path);
  886|    233|	sc_log(ctx, "Private key info path %s", ch_tmp);
  ------------------
  |  |   71|    233|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  887|       |
  888|    233|	kinfo.modulus_length	= size;
  889|    233|	kinfo.native		= 1;
  890|    233|	kinfo.key_reference	 = file_id & 0xFF;
  891|       |
  892|    233|	kinfo.usage = sc_oberthur_decode_usage(flags);
  893|    233|	kobj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    233|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  894|    233|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|    233|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (894:6): [True: 10, False: 223]
  ------------------
  895|     10|		kobj.flags |= SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     10|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  896|       |
  897|    233|	kobj.auth_id.len = sizeof(PinDomainID) > sizeof(kobj.auth_id.value)
  ------------------
  |  Branch (897:21): [Folded, False: 233]
  ------------------
  898|    233|			? sizeof(kobj.auth_id.value) : sizeof(PinDomainID);
  899|    233|	memcpy(kobj.auth_id.value, PinDomainID, kobj.auth_id.len);
  900|       |
  901|    233|	sc_log(ctx, "Parsed private key(reference:%i,usage:%X,flags:%X)", kinfo.key_reference, kinfo.usage, kobj.flags);
  ------------------
  |  |   71|    233|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  902|       |
  903|    233|	rv = sc_pkcs15emu_add_rsa_prkey(p15card, &kobj, &kinfo);
  904|    233|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    233|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    233|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    233|	int _ret = r; \
  |  |  |  |  155|    233|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 233, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    233|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 233]
  |  |  |  |  ------------------
  |  |  |  |  157|    233|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    233|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    233|	return _ret; \
  |  |  |  |  163|    233|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  905|    233|}
pkcs15-oberthur.c:sc_oberthur_get_friends:
  165|    334|{
  166|    334|	struct container *cont;
  167|       |
  168|  31.1k|	for (cont = Containers; cont; cont = cont->next)   {
  ------------------
  |  Branch (168:26): [True: 31.1k, False: 38]
  ------------------
  169|  31.1k|		if (cont->exchange.id_pub == id || cont->exchange.id_prv == id || cont->exchange.id_cert == id)   {
  ------------------
  |  Branch (169:7): [True: 266, False: 30.8k]
  |  Branch (169:38): [True: 19, False: 30.8k]
  |  Branch (169:69): [True: 1, False: 30.8k]
  ------------------
  170|    286|			if (ccont)
  ------------------
  |  Branch (170:8): [True: 286, False: 0]
  ------------------
  171|    286|				memcpy(ccont, &cont->exchange, sizeof(struct crypto_container));
  172|    286|			break;
  173|    286|		}
  174|       |
  175|  30.8k|		if (cont->sign.id_pub == id || cont->sign.id_prv == id || cont->sign.id_cert == id)   {
  ------------------
  |  Branch (175:7): [True: 6, False: 30.8k]
  |  Branch (175:34): [True: 3, False: 30.8k]
  |  Branch (175:61): [True: 1, False: 30.8k]
  ------------------
  176|     10|			if (ccont)
  ------------------
  |  Branch (176:8): [True: 10, False: 0]
  ------------------
  177|     10|				memcpy(ccont, &cont->sign, sizeof(struct crypto_container));
  178|     10|			break;
  179|     10|		}
  180|  30.8k|	}
  181|       |
  182|    334|	return cont ? 0 : SC_ERROR_TEMPLATE_NOT_FOUND;
  ------------------
  |  |  110|     38|#define SC_ERROR_TEMPLATE_NOT_FOUND		-1508
  ------------------
  |  Branch (182:9): [True: 296, False: 38]
  ------------------
  183|    334|}
pkcs15-oberthur.c:sc_oberthur_decode_usage:
  138|    271|{
  139|    271|	unsigned ret = 0;
  140|       |
  141|    271|	if (flags & OBERTHUR_ATTR_ENCRYPT)
  ------------------
  |  |   48|    271|#define OBERTHUR_ATTR_ENCRYPT		0x0008
  ------------------
  |  Branch (141:6): [True: 230, False: 41]
  ------------------
  142|    230|		ret |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|    230|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  143|    271|	if (flags & OBERTHUR_ATTR_DECRYPT)
  ------------------
  |  |   49|    271|#define OBERTHUR_ATTR_DECRYPT		0x0010
  ------------------
  |  Branch (143:6): [True: 223, False: 48]
  ------------------
  144|    223|		ret |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|    223|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  145|    271|	if (flags & OBERTHUR_ATTR_SIGN)
  ------------------
  |  |   50|    271|#define OBERTHUR_ATTR_SIGN		0x0020
  ------------------
  |  Branch (145:6): [True: 34, False: 237]
  ------------------
  146|     34|		ret |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|     34|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  147|    271|	if (flags & OBERTHUR_ATTR_RSIGN)
  ------------------
  |  |   52|    271|#define OBERTHUR_ATTR_RSIGN		0x0080
  ------------------
  |  Branch (147:6): [True: 231, False: 40]
  ------------------
  148|    231|		ret |= SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|    231|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  149|    271|	if (flags & OBERTHUR_ATTR_WRAP)
  ------------------
  |  |   54|    271|#define OBERTHUR_ATTR_WRAP		0x0200
  ------------------
  |  Branch (149:6): [True: 258, False: 13]
  ------------------
  150|    258|		ret |= SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|    258|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  151|    271|	if (flags & OBERTHUR_ATTR_UNWRAP)
  ------------------
  |  |   55|    271|#define OBERTHUR_ATTR_UNWRAP		0x0400
  ------------------
  |  Branch (151:6): [True: 12, False: 259]
  ------------------
  152|     12|		ret |= SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|     12|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  153|    271|	if (flags & OBERTHUR_ATTR_VERIFY)
  ------------------
  |  |   51|    271|#define OBERTHUR_ATTR_VERIFY		0x0040
  ------------------
  |  Branch (153:6): [True: 233, False: 38]
  ------------------
  154|    233|		ret |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|    233|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  155|    271|	if (flags & OBERTHUR_ATTR_RVERIFY)
  ------------------
  |  |   53|    271|#define OBERTHUR_ATTR_RVERIFY		0x0100
  ------------------
  |  Branch (155:6): [True: 5, False: 266]
  ------------------
  156|      5|		ret |= SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|      5|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  157|    271|	if (flags & OBERTHUR_ATTR_DERIVE)
  ------------------
  |  |   56|    271|#define OBERTHUR_ATTR_DERIVE		0x0800
  ------------------
  |  Branch (157:6): [True: 3, False: 268]
  ------------------
  158|      3|		ret |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      3|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  159|    271|	return ret;
  160|    271|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_data:
  911|     76|{
  912|     76|	struct sc_context *ctx = p15card->card->ctx;
  913|     76|	struct sc_pkcs15_data_info dinfo;
  914|     76|	struct sc_pkcs15_object dobj;
  915|     76|	unsigned flags;
  916|     76|	unsigned char *info_blob = NULL, *label = NULL, *app = NULL, *oid = NULL;
  917|     76|	size_t info_len, label_len, app_len, oid_len, offs;
  918|     76|	char ch_tmp[0x100];
  919|     76|	int rv;
  920|       |
  921|     76|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     76|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     76|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     76|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 76]
  |  |  ------------------
  ------------------
  922|     76|	sc_log(ctx, "Add data(file-id:%04X,size:%i,is-private:%i)", file_id, size, private);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  923|     76|	memset(&dinfo, 0, sizeof(dinfo));
  924|     76|	memset(&dobj, 0, sizeof(dobj));
  925|       |
  926|     76|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   76|     13|#define AWP_OBJECTS_DF_PRV	"3F0050119002"
  ------------------
              	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   75|     63|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  |  Branch (926:45): [True: 13, False: 63]
  ------------------
  927|       |
  928|     76|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  929|     76|	LOG_TEST_RET(ctx, rv, "Failed to add data: read oberthur file error");
  ------------------
  |  |  174|     76|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     76|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     76|	int _ret = (r); \
  |  |  |  |  168|     76|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 66]
  |  |  |  |  ------------------
  |  |  |  |  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|     76|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 66]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  930|       |
  931|     66|	if (info_len < 2) {
  ------------------
  |  Branch (931:6): [True: 1, False: 65]
  ------------------
  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|     65|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  936|     65|	offs = 2;
  937|       |
  938|       |	/* Label */
  939|     65|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (939:6): [True: 1, False: 64]
  ------------------
  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|     64|	label = info_blob + offs + 2;
  944|     64|	label_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  945|     64|	if (offs + 2 + label_len > info_len) {
  ------------------
  |  Branch (945:6): [True: 14, False: 50]
  ------------------
  946|     14|		free(info_blob);
  947|     14|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'label' received");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  948|     14|	}
  949|     50|	if (label_len > sizeof(dobj.label) - 1)
  ------------------
  |  Branch (949:6): [True: 11, False: 39]
  ------------------
  950|     11|		label_len = sizeof(dobj.label) - 1;
  951|     50|	offs += 2 + *(info_blob + offs + 1);
  952|       |
  953|       |	/* Application */
  954|     50|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (954:6): [True: 1, False: 49]
  ------------------
  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|     49|	app = info_blob + offs + 2;
  959|     49|	app_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  960|     49|	if (offs + 2 + app_len > info_len) {
  ------------------
  |  Branch (960:6): [True: 8, False: 41]
  ------------------
  961|      8|		free(info_blob);
  962|      8|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'application' received");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  963|      8|	}
  964|     41|	if (app_len > sizeof(dinfo.app_label) - 1)
  ------------------
  |  Branch (964:6): [True: 3, False: 38]
  ------------------
  965|      3|		app_len = sizeof(dinfo.app_label) - 1;
  966|     41|	offs += 2 + app_len;
  967|       |
  968|       |	/* OID encode like DER(ASN.1(oid)) */
  969|     41|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (969:6): [True: 1, False: 40]
  ------------------
  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|     40|	oid_len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  974|     40|	if (offs + 2 + oid_len > info_len) {
  ------------------
  |  Branch (974:6): [True: 12, False: 28]
  ------------------
  975|     12|		free(info_blob);
  976|     12|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of 'oid' received");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  977|     12|	}
  978|     28|	if (oid_len > 2) {
  ------------------
  |  Branch (978:6): [True: 5, False: 23]
  ------------------
  979|      5|		oid = info_blob + offs + 2;
  980|      5|		if (*oid != 0x06 || (*(oid + 1) != oid_len - 2)) {
  ------------------
  |  Branch (980:7): [True: 3, False: 2]
  |  Branch (980:23): [True: 1, False: 1]
  ------------------
  981|      4|			free(info_blob);
  982|      4|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Failed to add data: invalid 'OID' format");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  983|      4|		}
  984|      1|		oid += 2;
  985|      1|		oid_len -= 2;
  986|      1|	}
  987|       |
  988|     24|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   76|      5|#define AWP_OBJECTS_DF_PRV	"3F0050119002"
  ------------------
              	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", private ? AWP_OBJECTS_DF_PRV : AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   75|     19|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  |  Branch (988:45): [True: 5, False: 19]
  ------------------
  989|       |
  990|     24|	sc_format_path(ch_tmp, &dinfo.path);
  991|       |
  992|     24|	memcpy(dobj.label, label, label_len);
  993|     24|	memcpy(dinfo.app_label, app, app_len);
  994|     24|	if (oid_len)
  ------------------
  |  Branch (994:6): [True: 3, False: 21]
  ------------------
  995|      3|		sc_asn1_decode_object_id(oid, oid_len, &dinfo.app_oid);
  996|       |
  997|     24|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|     24|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (997:6): [True: 10, False: 14]
  ------------------
  998|     10|		dobj.flags |= SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     10|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  999|       |
 1000|     24|	if (private)   {
  ------------------
  |  Branch (1000:6): [True: 5, False: 19]
  ------------------
 1001|      5|		dobj.auth_id.len = sizeof(PinDomainID) > sizeof(dobj.auth_id.value)
  ------------------
  |  Branch (1001:22): [Folded, False: 5]
  ------------------
 1002|      5|				? sizeof(dobj.auth_id.value) : sizeof(PinDomainID);
 1003|      5|		memcpy(dobj.auth_id.value, PinDomainID, dobj.auth_id.len);
 1004|       |
 1005|      5|		dobj.flags |= SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|      5|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1006|      5|	}
 1007|       |
 1008|     24|	rv = sc_pkcs15emu_add_data_object(p15card, &dobj, &dinfo);
 1009|       |
 1010|     24|	free(info_blob);
 1011|     24|	LOG_FUNC_RETURN(p15card->card->ctx, rv);
  ------------------
  |  |  164|     24|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     24|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     24|	int _ret = r; \
  |  |  |  |  155|     24|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  157|     24|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     24|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     24|	return _ret; \
  |  |  |  |  163|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1012|     24|}
pkcs15-oberthur.c:sc_awp_clear:
 1210|  1.54k|{
 1211|  1.54k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  1.54k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.54k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.54k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.54k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.54k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1212|  1.54k|}
pkcs15-oberthur.c:sc_oberthur_parse_tokeninfo:
  365|    469|{
  366|    469|	struct sc_context *ctx = p15card->card->ctx;
  367|    469|	char label[0x21];
  368|    469|	unsigned flags;
  369|    469|	int ii;
  370|       |
  371|    469|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    469|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    469|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    469|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    469|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 469]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  372|    469|	if (!buff || len < 0x24)
  ------------------
  |  Branch (372:6): [True: 0, False: 469]
  |  Branch (372:15): [True: 24, False: 445]
  ------------------
  373|    469|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Cannot parse token info");
  ------------------
  |  |  174|     24|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     24|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     24|	int _ret = (r); \
  |  |  |  |  168|     24|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     24|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     24|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     24|		return _ret; \
  |  |  |  |  172|     24|	} \
  |  |  |  |  173|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  374|       |
  375|    445|	memset(label, 0, sizeof(label));
  376|       |
  377|    445|	memcpy(label, buff, 0x20);
  378|    445|	ii = 0x20;
  379|    524|	while (*(label + --ii)==' ' && ii)
  ------------------
  |  Branch (379:9): [True: 80, False: 444]
  |  Branch (379:33): [True: 79, False: 1]
  ------------------
  380|     79|		;
  381|    445|	*(label + ii + 1) = '\0';
  382|       |
  383|    445|	flags = *(buff + 0x22) * 0x100 + *(buff + 0x23);
  384|       |
  385|    445|	set_string(&p15card->tokeninfo->label, label);
  386|    445|	set_string(&p15card->tokeninfo->manufacturer_id, "Oberthur/OpenSC");
  387|       |
  388|    445|	if (flags & 0x01)
  ------------------
  |  Branch (388:6): [True: 1, False: 444]
  ------------------
  389|      1|		p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_PRN_GENERATION;
  ------------------
  |  |  597|      1|#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
  ------------------
  390|       |
  391|    445|	sc_log(ctx, "label %s", p15card->tokeninfo->label);
  ------------------
  |  |   71|    445|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  392|    445|	sc_log(ctx, "manufacturer_id %s", p15card->tokeninfo->manufacturer_id);
  ------------------
  |  |   71|    445|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  393|       |
  394|    445|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    445|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    445|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    445|	int _ret = r; \
  |  |  |  |  155|    445|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 445, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    445|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 445]
  |  |  |  |  ------------------
  |  |  |  |  157|    445|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    445|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    445|	return _ret; \
  |  |  |  |  163|    445|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|    445|}
pkcs15-oberthur.c:sc_oberthur_parse_containers:
  401|    422|{
  402|    422|	struct sc_context *ctx = p15card->card->ctx;
  403|    422|	size_t offs;
  404|       |
  405|    422|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    422|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    422|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    422|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    422|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 422]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  406|       |
  407|  21.7k|	while (Containers)   {
  ------------------
  |  Branch (407:9): [True: 21.3k, False: 422]
  ------------------
  408|  21.3k|		struct container *next = Containers->next;
  409|       |
  410|  21.3k|		free (Containers);
  411|  21.3k|		Containers = next;
  412|  21.3k|	}
  413|       |
  414|  21.7k|	for (offs=0; offs + 2 + 2+2+2 + 2+2+2 + 2+36 <= len;)  {
  ------------------
  |  Branch (414:15): [True: 21.3k, False: 419]
  ------------------
  415|  21.3k|		struct container *cont;
  416|  21.3k|		unsigned char *ptr =  buff + offs + 2;
  417|       |
  418|  21.3k|		sc_log(ctx,
  ------------------
  |  |   71|  21.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__
  |  |  ------------------
  ------------------
  419|  21.3k|		       "parse contaniers offs:%"SC_FORMAT_LEN_SIZE_T"u, len:%"SC_FORMAT_LEN_SIZE_T"u",
  420|  21.3k|		       offs, len);
  421|  21.3k|		if (*(buff + offs) != 'R')
  ------------------
  |  Branch (421:7): [True: 3, False: 21.3k]
  ------------------
  422|      3|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  423|       |
  424|  21.3k|		cont = (struct container *)calloc(1, sizeof(struct container));
  425|  21.3k|		if (!cont)
  ------------------
  |  Branch (425:7): [True: 0, False: 21.3k]
  ------------------
  426|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  427|       |
  428|  21.3k|		cont->exchange.id_pub = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  429|  21.3k|		cont->exchange.id_prv = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  430|  21.3k|		cont->exchange.id_cert = *ptr * 0x100 + *(ptr + 1); ptr += 2;
  431|       |
  432|  21.3k|		cont->sign.id_pub = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  433|  21.3k|		cont->sign.id_prv = *ptr * 0x100 + *(ptr + 1);  ptr += 2;
  434|  21.3k|		cont->sign.id_cert = *ptr * 0x100 + *(ptr + 1); ptr += 2;
  435|       |
  436|  21.3k|		memcpy(cont->uuid, ptr + 2, 36);
  437|  21.3k|		sc_log(ctx, "UUID: %s; 0x%X, 0x%X, 0x%X", cont->uuid,
  ------------------
  |  |   71|  21.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__
  |  |  ------------------
  ------------------
  438|  21.3k|				cont->exchange.id_pub, cont->exchange.id_prv, cont->exchange.id_cert);
  439|       |
  440|  21.3k|		if (!Containers)  {
  ------------------
  |  Branch (440:7): [True: 237, False: 21.0k]
  ------------------
  441|    237|			Containers = cont;
  442|    237|		}
  443|  21.0k|		else   {
  444|  21.0k|			cont->next = Containers;
  445|  21.0k|			Containers->prev = (void *)cont;
  446|  21.0k|			Containers = cont;
  447|  21.0k|		}
  448|       |
  449|  21.3k|		offs += *(buff + offs + 1) + 2;
  450|  21.3k|	}
  451|       |
  452|    419|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    419|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    419|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    419|	int _ret = r; \
  |  |  |  |  155|    419|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 419, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    419|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 419]
  |  |  |  |  ------------------
  |  |  |  |  157|    419|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    419|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    419|	return _ret; \
  |  |  |  |  163|    419|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  453|    419|}
pkcs15-oberthur.c:sc_oberthur_parse_publicinfo:
  459|    403|{
  460|    403|	struct sc_context *ctx = p15card->card->ctx;
  461|    403|	size_t ii;
  462|    403|	int rv;
  463|       |
  464|    403|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    403|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    403|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    403|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    403|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 403]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|  30.3k|	for (ii=0; ii+5<=len; ii+=5)   {
  ------------------
  |  Branch (465:13): [True: 30.0k, False: 266]
  ------------------
  466|  30.0k|		unsigned int file_id, size;
  467|       |
  468|  30.0k|		if(*(buff+ii) != 0xFF)
  ------------------
  |  Branch (468:6): [True: 29.8k, False: 175]
  ------------------
  469|  29.8k|			continue;
  470|       |
  471|    175|		file_id = 0x100 * *(buff+ii + 1) + *(buff+ii + 2);
  472|    175|		size = 0x100 * *(buff+ii + 3) + *(buff+ii + 4);
  473|    175|		sc_log(ctx, "add public object(file-id:%04X,size:%X)", file_id, size);
  ------------------
  |  |   71|    175|#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|    175|		switch (*(buff+ii + 1))   {
  476|     44|		case BASE_ID_PUB_RSA :
  ------------------
  |  |   81|     44|#define BASE_ID_PUB_RSA   0x10
  ------------------
  |  Branch (476:3): [True: 44, False: 131]
  ------------------
  477|     44|			rv = sc_pkcs15emu_oberthur_add_pubkey(p15card, file_id, size);
  478|     44|			LOG_TEST_RET(ctx, rv, "Cannot parse public key info");
  ------------------
  |  |  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: 35, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  479|      9|			break;
  480|     41|		case BASE_ID_CERT :
  ------------------
  |  |   82|     41|#define BASE_ID_CERT	  0x20
  ------------------
  |  Branch (480:3): [True: 41, False: 134]
  ------------------
  481|     41|			rv = sc_pkcs15emu_oberthur_add_cert(p15card, file_id);
  482|     41|			LOG_TEST_RET(ctx, rv, "Cannot parse certificate info");
  ------------------
  |  |  174|     41|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     41|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     41|	int _ret = (r); \
  |  |  |  |  168|     41|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 41, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     41|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     41|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     41|		return _ret; \
  |  |  |  |  172|     41|	} \
  |  |  |  |  173|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  483|      0|			break;
  484|     10|		case BASE_ID_PUB_DES :
  ------------------
  |  |   87|     10|#define BASE_ID_PUB_DES   0x70
  ------------------
  |  Branch (484:3): [True: 10, False: 165]
  ------------------
  485|     10|			break;
  486|     63|		case BASE_ID_PUB_DATA :
  ------------------
  |  |   85|     63|#define BASE_ID_PUB_DATA  0x50
  ------------------
  |  Branch (486:3): [True: 63, False: 112]
  ------------------
  487|     63|			rv = sc_pkcs15emu_oberthur_add_data(p15card, file_id, size, 0);
  488|     63|			LOG_TEST_RET(ctx, rv, "Cannot parse data info");
  ------------------
  |  |  174|     63|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     63|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     63|	int _ret = (r); \
  |  |  |  |  168|     63|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 44, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  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|     63|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  489|     19|			break;
  490|     19|		default:
  ------------------
  |  Branch (490:3): [True: 17, False: 158]
  ------------------
  491|     17|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Public object parse error");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  492|    175|		}
  493|    175|	}
  494|       |
  495|    266|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    266|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    266|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    266|	int _ret = r; \
  |  |  |  |  155|    266|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 266, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    266|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 266]
  |  |  |  |  ------------------
  |  |  |  |  157|    266|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    266|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    266|	return _ret; \
  |  |  |  |  163|    266|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  496|    266|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_pubkey:
  576|     44|{
  577|     44|	struct sc_context *ctx = p15card->card->ctx;
  578|     44|	struct sc_pkcs15_pubkey_info key_info;
  579|     44|	struct sc_pkcs15_object key_obj;
  580|     44|	char ch_tmp[0x100];
  581|     44|	unsigned char *info_blob = NULL;
  582|     44|	size_t len, info_len, offs;
  583|     44|	unsigned flags;
  584|     44|	int rv;
  585|       |
  586|     44|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  587|     44|	sc_log(ctx, "public key(file-id:%04X,size:%X)", file_id, size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  588|       |
  589|     44|	memset(&key_info, 0, sizeof(key_info));
  590|     44|	memset(&key_obj, 0, sizeof(key_obj));
  591|       |
  592|     44|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   75|     44|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  593|     44|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  594|     44|	LOG_TEST_RET(ctx, rv, "Failed to add public key: read oberthur file error");
  ------------------
  |  |  174|     44|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     44|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     44|	int _ret = (r); \
  |  |  |  |  168|     44|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 39]
  |  |  |  |  ------------------
  |  |  |  |  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|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 39]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  595|       |
  596|       |	/* Flags */
  597|     39|	offs = 2;
  598|     39|	if (offs > info_len) {
  ------------------
  |  Branch (598:6): [True: 1, False: 38]
  ------------------
  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|     38|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  603|     38|	key_info.usage = sc_oberthur_decode_usage(flags);
  604|     38|	if (flags & OBERTHUR_ATTR_MODIFIABLE)
  ------------------
  |  |   45|     38|#define OBERTHUR_ATTR_MODIFIABLE	0x0001
  ------------------
  |  Branch (604:6): [True: 9, False: 29]
  ------------------
  605|      9|		key_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|      9|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  606|     38|	sc_log(ctx, "Public key key-usage:%04X", key_info.usage);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  607|       |
  608|       |	/* Label */
  609|     38|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (609:6): [True: 1, False: 37]
  ------------------
  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|     37|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  614|     37|	if (offs + 2 + len > info_len) {
  ------------------
  |  Branch (614:6): [True: 7, False: 30]
  ------------------
  615|      7|		free(info_blob);
  616|      7|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add public key: invalid 'Label' length");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  617|     30|	} else if (len) {
  ------------------
  |  Branch (617:13): [True: 16, False: 14]
  ------------------
  618|     16|		if (len > sizeof(key_obj.label) - 1)
  ------------------
  |  Branch (618:7): [True: 2, False: 14]
  ------------------
  619|      2|			len = sizeof(key_obj.label) - 1;
  620|     16|		memcpy(key_obj.label, info_blob + offs + 2, len);
  621|     16|	}
  622|     30|	offs += 2 + len;
  623|       |
  624|       |	/* ID */
  625|     30|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (625:6): [True: 1, False: 29]
  ------------------
  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|     29|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  630|     29|	if (len == 0
  ------------------
  |  Branch (630:6): [True: 7, False: 22]
  ------------------
  631|     22|			|| len > sizeof(key_info.id.value)
  ------------------
  |  Branch (631:7): [True: 12, False: 10]
  ------------------
  632|     20|			|| offs + 2 + len > info_len) {
  ------------------
  |  Branch (632:7): [True: 1, False: 9]
  ------------------
  633|     20|		free(info_blob);
  634|     20|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add public key: invalid 'ID' length");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  635|     20|	}
  636|      9|	memcpy(key_info.id.value, info_blob + offs + 2, len);
  637|      9|	key_info.id.len = len;
  638|       |
  639|      9|	free(info_blob);
  640|       |
  641|       |	/* Ignore Start/End dates */
  642|       |
  643|      9|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   75|      9|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  644|      9|	sc_format_path(ch_tmp, &key_info.path);
  645|       |
  646|      9|	key_info.native = 1;
  647|      9|	key_info.key_reference = file_id & 0xFF;
  648|      9|	key_info.modulus_length = size;
  649|       |
  650|      9|	rv = sc_pkcs15emu_add_rsa_pubkey(p15card, &key_obj, &key_info);
  651|       |
  652|      9|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      9|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      9|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      9|	int _ret = r; \
  |  |  |  |  155|      9|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      9|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  157|      9|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      9|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      9|	return _ret; \
  |  |  |  |  163|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  653|      9|}
pkcs15-oberthur.c:sc_pkcs15emu_oberthur_add_cert:
  666|     41|{
  667|     41|	struct sc_context *ctx = p15card->card->ctx;
  668|     41|	struct sc_pkcs15_cert_info cinfo;
  669|     41|	struct sc_pkcs15_object cobj;
  670|     41|	unsigned char *info_blob = NULL, *cert_blob = NULL;
  671|     41|	size_t info_len, cert_len, len, offs;
  672|     41|	unsigned flags;
  673|     41|	int rv;
  674|     41|	char ch_tmp[0x20];
  675|       |
  676|     41|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     41|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     41|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     41|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     41|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 41]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|     41|	sc_log(ctx, "add certificate(file-id:%04X)", file_id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  678|       |
  679|     41|	memset(&cinfo, 0, sizeof(cinfo));
  680|     41|	memset(&cobj, 0, sizeof(cobj));
  681|       |
  682|     41|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id | 0x100);
  ------------------
  |  |   75|     41|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  683|     41|	rv = sc_oberthur_read_file(p15card, ch_tmp, &info_blob, &info_len, 1);
  684|     41|	LOG_TEST_RET(ctx, rv, "Failed to add certificate: read oberthur file error");
  ------------------
  |  |  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: 6, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  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|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  685|       |
  686|     35|	if (info_len < 2) {
  ------------------
  |  Branch (686:6): [True: 1, False: 34]
  ------------------
  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|     34|	flags = *(info_blob + 0) * 0x100 + *(info_blob + 1);
  691|     34|	offs = 2;
  692|       |
  693|       |	/* Label */
  694|     34|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (694:6): [True: 1, False: 33]
  ------------------
  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|     33|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  699|     33|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (699:6): [True: 6, False: 27]
  ------------------
  700|      6|		free(info_blob);
  701|      6|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'CN' length");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  702|     27|	} else if (len) {
  ------------------
  |  Branch (702:13): [True: 20, False: 7]
  ------------------
  703|     20|		if (len > sizeof(cobj.label) - 1)
  ------------------
  |  Branch (703:7): [True: 8, False: 12]
  ------------------
  704|      8|			len = sizeof(cobj.label) - 1;
  705|     20|		memcpy(cobj.label, info_blob + offs + 2, len);
  706|     20|	}
  707|     27|	offs += 2 + len;
  708|       |
  709|       |	/* ID */
  710|     27|	if (offs + 2 > info_len) {
  ------------------
  |  Branch (710:6): [True: 1, False: 26]
  ------------------
  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|     26|	len = *(info_blob + offs + 1) + *(info_blob + offs) * 0x100;
  715|     26|	if (len + offs + 2 > info_len) {
  ------------------
  |  Branch (715:6): [True: 10, False: 16]
  ------------------
  716|     10|		free(info_blob);
  717|     10|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid 'ID' length");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  718|     16|	} else if (len > sizeof(cinfo.id.value)) {
  ------------------
  |  Branch (718:13): [True: 3, False: 13]
  ------------------
  719|      3|		free(info_blob);
  720|      3|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Failed to add certificate: invalid 'ID' length");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  721|      3|	}
  722|     13|	memcpy(cinfo.id.value, info_blob + offs + 2, len);
  723|     13|	cinfo.id.len = len;
  724|       |
  725|     13|	free(info_blob);
  726|       |
  727|       |	/* Ignore subject, issuer and serial */
  728|       |
  729|     13|	snprintf(ch_tmp, sizeof(ch_tmp), "%s%04X", AWP_OBJECTS_DF_PUB, file_id);
  ------------------
  |  |   75|     13|#define AWP_OBJECTS_DF_PUB	"3F0050119001"
  ------------------
  730|     13|	sc_format_path(ch_tmp, &cinfo.path);
  731|     13|	rv = sc_oberthur_read_file(p15card, ch_tmp, &cert_blob, &cert_len, 1);
  732|     13|	LOG_TEST_RET(ctx, rv, "Failed to add certificate: read certificate error");
  ------------------
  |  |  174|     13|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     13|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     13|	int _ret = (r); \
  |  |  |  |  168|     13|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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|     13|} 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.09k|{
  239|  2.09k|	struct sc_context *ctx = p15card->card->ctx;
  240|  2.09k|	struct sc_card *card = p15card->card;
  241|  2.09k|	struct sc_file *file = NULL;
  242|  2.09k|	struct sc_path path;
  243|  2.09k|	size_t sz;
  244|  2.09k|	int rv;
  245|       |
  246|  2.09k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.09k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.09k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  247|  2.09k|	if (!in_path || !out || !out_len)
  ------------------
  |  Branch (247:6): [True: 0, False: 2.09k]
  |  Branch (247:18): [True: 0, False: 2.09k]
  |  Branch (247:26): [True: 0, False: 2.09k]
  ------------------
  248|  2.09k|		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.09k|	sc_log(ctx, "read file '%s'; verify_pin:%i", in_path, verify_pin);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  251|       |
  252|  2.09k|	*out = NULL;
  253|  2.09k|	*out_len = 0;
  254|       |
  255|  2.09k|	sc_format_path(in_path, &path);
  256|  2.09k|	rv = sc_select_file(card, &path, &file);
  257|  2.09k|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|  2.09k|#define SC_SUCCESS				0
  ------------------
  |  Branch (257:6): [True: 114, False: 1.98k]
  ------------------
  258|    114|		sc_file_free(file);
  259|    114|		LOG_TEST_RET(ctx, rv, "Cannot select oberthur file to read");
  ------------------
  |  |  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: 114, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    114|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|    114|	}
  261|       |
  262|  1.98k|	if (file->ef_structure == SC_FILE_EF_TRANSPARENT)
  ------------------
  |  |  221|  1.98k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (262:6): [True: 104, False: 1.87k]
  ------------------
  263|    104|		sz = file->size;
  264|  1.87k|	else
  265|  1.87k|		sz = (file->record_length + 2) * file->record_count;
  266|       |
  267|  1.98k|	*out = calloc(1, sz);
  268|  1.98k|	if (*out == NULL) {
  ------------------
  |  Branch (268:6): [True: 0, False: 1.98k]
  ------------------
  269|      0|		sc_file_free(file);
  270|      0|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot read oberthur file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  271|      0|	}
  272|       |
  273|  1.98k|	if (file->ef_structure == SC_FILE_EF_TRANSPARENT)   {
  ------------------
  |  |  221|  1.98k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (273:6): [True: 104, False: 1.87k]
  ------------------
  274|    104|		rv = sc_read_binary(card, 0, *out, sz, 0);
  275|    104|	}
  276|  1.87k|	else	{
  277|  1.87k|		unsigned int rec;
  278|  1.87k|		size_t offs = 0;
  279|  1.87k|		size_t rec_len = file->record_length;
  280|       |
  281|   168k|		for (rec = 1; ; rec++)   {
  282|   168k|			if (rec > file->record_count) {
  ------------------
  |  Branch (282:8): [True: 1.85k, False: 166k]
  ------------------
  283|  1.85k|				rv = 0;
  284|  1.85k|				break;
  285|  1.85k|			}
  286|   166k|			rv = sc_read_record(card, rec, 0, *out + offs + 2, rec_len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1305|   166k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  287|   166k|			if (rv == SC_ERROR_RECORD_NOT_FOUND)   {
  ------------------
  |  |   52|   166k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (287:8): [True: 1, False: 166k]
  ------------------
  288|      1|				rv = 0;
  289|      1|				break;
  290|      1|			}
  291|   166k|			else if (rv < 0)   {
  ------------------
  |  Branch (291:13): [True: 24, False: 166k]
  ------------------
  292|     24|				break;
  293|     24|			}
  294|       |
  295|   166k|			rec_len = rv;
  296|       |
  297|   166k|			*(*out + offs) = 'R';
  298|   166k|			*(*out + offs + 1) = rv;
  299|       |
  300|   166k|			offs += rv + 2;
  301|   166k|		}
  302|       |
  303|  1.87k|		sz = offs;
  304|  1.87k|	}
  305|       |
  306|  1.98k|	sc_log(ctx, "read oberthur file result %i", rv);
  ------------------
  |  |   71|  1.98k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  307|  1.98k|	if (verify_pin && rv == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)   {
  ------------------
  |  |   61|  1.98k|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (307:6): [True: 1.98k, False: 0]
  |  Branch (307:20): [True: 4, False: 1.97k]
  ------------------
  308|      4|		struct sc_pkcs15_object *objs[0x10], *pin_obj = NULL;
  309|      4|		const struct sc_acl_entry *acl = sc_file_get_acl_entry(file, SC_AC_OP_READ);
  ------------------
  |  |  188|      4|#define SC_AC_OP_READ			22
  ------------------
  310|      4|		int ii, nobjs;
  311|       |
  312|      4|		if (acl == NULL) {
  ------------------
  |  Branch (312:7): [True: 2, False: 2]
  ------------------
  313|      2|			sc_file_free(file);
  314|      2|			free(*out);
  315|      2|			*out = NULL;
  316|      2|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|      2|		}
  318|       |
  319|      2|		nobjs = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 0x10);
  ------------------
  |  |  445|      2|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  320|      2|		if (nobjs < 1) {
  ------------------
  |  Branch (320:7): [True: 0, False: 2]
  ------------------
  321|      0|			sc_file_free(file);
  322|      0|			free(*out);
  323|      0|			*out = NULL;
  324|      0|			LOG_TEST_RET(ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|      0|				"Cannot read oberthur file: get AUTH objects error");
  326|      0|		}
  327|       |
  328|      3|		for (ii = 0; ii < nobjs; ii++) {
  ------------------
  |  Branch (328:16): [True: 2, False: 1]
  ------------------
  329|      2|			struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *) objs[ii]->data;
  330|      2|			sc_log(ctx, "compare PIN/ACL refs:%i/%i, method:%i/%i",
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  331|      2|				auth_info->attrs.pin.reference, acl->key_ref, auth_info->auth_method, acl->method);
  332|      2|			if (auth_info->attrs.pin.reference == (int)acl->key_ref && auth_info->auth_method == (unsigned)acl->method)   {
  ------------------
  |  Branch (332:8): [True: 1, False: 1]
  |  Branch (332:63): [True: 1, False: 0]
  ------------------
  333|      1|				pin_obj = objs[ii];
  334|      1|				break;
  335|      1|			}
  336|      2|		}
  337|       |
  338|      2|		if (!pin_obj || !pin_obj->content.value)    {
  ------------------
  |  Branch (338:7): [True: 1, False: 1]
  |  Branch (338:19): [True: 1, False: 0]
  ------------------
  339|      2|			rv = SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      2|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  340|      2|		}
  341|      0|		else    {
  342|      0|			rv = sc_pkcs15_verify_pin(p15card, pin_obj, pin_obj->content.value, pin_obj->content.len);
  343|      0|			if (!rv)
  ------------------
  |  Branch (343:8): [True: 0, False: 0]
  ------------------
  344|      0|				rv = sc_oberthur_read_file(p15card, in_path, out, out_len, 0);
  345|      0|		}
  346|      2|	}
  347|       |
  348|  1.97k|	sc_file_free(file);
  349|       |
  350|  1.97k|	if (rv < 0)   {
  ------------------
  |  Branch (350:6): [True: 25, False: 1.95k]
  ------------------
  351|     25|		free(*out);
  352|     25|		*out = NULL;
  353|     25|		*out_len = 0;
  354|     25|	}
  355|       |
  356|  1.97k|	*out_len = sz;
  357|       |
  358|  1.97k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  1.97k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.97k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.97k|	int _ret = r; \
  |  |  |  |  155|  1.97k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.89k, False: 86]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.89k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     25|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 25, False: 1.86k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.89k|	} else { \
  |  |  |  |  159|     86|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     86|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     86|	} \
  |  |  |  |  162|  1.97k|	return _ret; \
  |  |  |  |  163|  1.97k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  359|  1.97k|}

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

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.93k|{
  300|  6.93k|	struct sc_context *ctx = p15card->card->ctx;
  301|  6.93k|	struct sc_pkcs15_auth_info *auth_info;
  302|  6.93k|	int r;
  303|       |
  304|  6.93k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  6.93k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.93k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.93k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.93k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.93k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|       |
  306|  6.93k|	if (!pin_obj || !pin_obj->data)
  ------------------
  |  Branch (306:6): [True: 0, False: 6.93k]
  |  Branch (306:18): [True: 0, False: 6.93k]
  ------------------
  307|  6.93k|		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.93k|	auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  309|       |
  310|       |	/* Check the provided pin matches pin requirements */
  311|  6.93k|	r = _validate_pin(p15card, auth_info, pinlen);
  312|       |
  313|  6.93k|	if (r)
  ------------------
  |  Branch (313:6): [True: 6.08k, False: 853]
  ------------------
  314|  6.93k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  6.08k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.08k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.08k|	int _ret = r; \
  |  |  |  |  155|  6.08k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.08k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.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|  6.08k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.08k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.08k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.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|  6.08k|	return _ret; \
  |  |  |  |  163|  6.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|       |
  316|    853|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pincode, pinlen);
  317|       |
  318|    853|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    853|#define SC_SUCCESS				0
  ------------------
  |  Branch (318:6): [True: 248, False: 605]
  ------------------
  319|    248|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  320|       |
  321|    853|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    853|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    853|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    853|	int _ret = r; \
  |  |  |  |  155|    853|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 853, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    853|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 248]
  |  |  |  |  ------------------
  |  |  |  |  157|    853|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    853|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    853|	return _ret; \
  |  |  |  |  163|    853|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  322|    853|}
_sc_pkcs15_verify_pin:
  328|  1.15k|{
  329|  1.15k|	return sc_pkcs15_verify_pin_with_session_pin(p15card, pin_obj, pincode,
  330|  1.15k|			pinlen, NULL, NULL);
  331|  1.15k|}
sc_pkcs15_verify_pin_with_session_pin:
  344|  1.15k|{
  345|  1.15k|	struct sc_context *ctx = p15card->card->ctx;
  346|  1.15k|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  347|  1.15k|	int r;
  348|  1.15k|	sc_card_t *card;
  349|  1.15k|	struct sc_pin_cmd_data data;
  350|       |
  351|  1.15k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.15k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.15k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.15k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.15k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|  1.15k|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  353|  1.15k|	       "PIN(type:%X; method:%X; value(%p:%"SC_FORMAT_LEN_SIZE_T"u)",
  354|  1.15k|	       auth_info->auth_type, auth_info->auth_method,
  355|  1.15k|	       pincode, pinlen);
  356|  1.15k|	card = p15card->card;
  357|       |
  358|  1.15k|	if (pinlen > SC_MAX_PIN_SIZE) {
  ------------------
  |  |   40|  1.15k|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (358:6): [True: 0, False: 1.15k]
  ------------------
  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.15k|	memset(&data, 0, sizeof(data));
  366|  1.15k|	data.pin_type = auth_info->auth_method;
  367|       |
  368|  1.15k|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|  1.15k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (368:6): [True: 1.15k, False: 0]
  ------------------
  369|  1.15k|		data.pin_reference = auth_info->attrs.pin.reference;
  370|  1.15k|		data.pin1.min_length = auth_info->attrs.pin.min_length;
  371|  1.15k|		data.pin1.max_length = auth_info->attrs.pin.max_length;
  372|  1.15k|		data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  373|  1.15k|		data.pin1.pad_char = auth_info->attrs.pin.pad_char;
  374|  1.15k|		data.pin1.data = pincode;
  375|  1.15k|		data.pin1.len = pinlen;
  376|       |
  377|  1.15k|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|  1.15k|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (377:7): [True: 323, False: 834]
  ------------------
  378|    323|			data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|    323|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  379|       |
  380|  1.15k|		switch (auth_info->attrs.pin.type) {
  381|     11|		case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|     11|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (381:3): [True: 11, False: 1.14k]
  ------------------
  382|     11|			data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  433|     11|#define SC_PIN_ENCODING_BCD	1
  ------------------
  383|     11|			break;
  384|    701|		case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    701|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (384:3): [True: 701, False: 456]
  ------------------
  385|    701|			data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|    701|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  386|    701|			break;
  387|    445|		default:
  ------------------
  |  Branch (387:3): [True: 445, False: 712]
  ------------------
  388|       |			/* assume/hope the card driver knows how to encode the pin */
  389|    445|			data.pin1.encoding = 0;
  390|  1.15k|		}
  391|  1.15k|	}
  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.15k|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  383|  2.31k|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (408:7): [True: 0, False: 1.15k]
  ------------------
  409|  1.15k|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  567|  1.15k|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (409:8): [True: 0, False: 1.15k]
  ------------------
  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.15k|	if (card->caps & SC_CARD_CAP_SESSION_PIN && sessionpin && sessionpinlen) {
  ------------------
  |  |  570|  2.31k|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
  |  Branch (419:6): [True: 0, False: 1.15k]
  |  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.15k|	} else {
  426|       |		/* perform a standard verify */
  427|  1.15k|		data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  422|  1.15k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  428|  1.15k|		if (sessionpinlen)
  ------------------
  |  Branch (428:7): [True: 0, False: 1.15k]
  ------------------
  429|      0|			*sessionpinlen = 0;
  430|  1.15k|	}
  431|       |
  432|  1.15k|	r = sc_lock(card);
  433|  1.15k|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  1.15k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.15k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.15k|	int _ret = (r); \
  |  |  |  |  168|  1.15k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.15k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.15k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  434|       |
  435|       |	/* the path in the pin object is optional */
  436|  1.15k|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (436:6): [True: 433, False: 724]
  |  Branch (436:35): [True: 29, False: 695]
  ------------------
  437|    462|		r = sc_select_file(card, &auth_info->path, NULL);
  438|    462|		if (r)
  ------------------
  |  Branch (438:7): [True: 53, False: 409]
  ------------------
  439|     53|			goto out;
  440|    462|	}
  441|       |
  442|  1.10k|	r = sc_pin_cmd(card, &data);
  443|  1.10k|	auth_info->tries_left = data.pin1.tries_left;
  444|  1.10k|	sc_log(ctx, "PIN cmd result %i", 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__
  |  |  ------------------
  ------------------
  445|  1.10k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.10k|#define SC_SUCCESS				0
  ------------------
  |  Branch (445:6): [True: 524, False: 580]
  ------------------
  446|    524|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  447|    524|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  426|  1.04k|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (447:7): [True: 0, False: 524]
  |  Branch (447:49): [True: 0, False: 0]
  ------------------
  448|      0|			*sessionpinlen = data.pin2.len;
  449|      0|		}
  450|    580|	} else {
  451|    580|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  452|    580|				NOTIFY_PIN_BAD);
  453|    580|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  426|  1.16k|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (453:7): [True: 0, False: 580]
  |  Branch (453:49): [True: 0, False: 0]
  ------------------
  454|      0|			*sessionpinlen = 0;
  455|      0|		}
  456|    580|	}
  457|       |
  458|  1.10k|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN
  ------------------
  |  |   94|  2.20k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (458:6): [True: 1.10k, False: 0]
  ------------------
  459|  1.10k|			&& auth_info->auth_method != SC_AC_SESSION) {
  ------------------
  |  |  159|  1.10k|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (459:7): [True: 1.10k, False: 0]
  ------------------
  460|  1.10k|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  461|  1.10k|				r == SC_SUCCESS ? NOTIFY_PIN_GOOD : NOTIFY_PIN_BAD);
  ------------------
  |  |   28|  1.10k|#define SC_SUCCESS				0
  ------------------
  |  Branch (461:5): [True: 524, False: 580]
  ------------------
  462|  1.10k|	}
  463|       |
  464|  1.15k|out:
  465|  1.15k|	sc_unlock(card);
  466|  1.15k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  1.15k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.15k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.15k|	int _ret = r; \
  |  |  |  |  155|  1.15k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.15k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.15k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    633|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 633, False: 524]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.15k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.15k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.15k|	return _ret; \
  |  |  |  |  163|  1.15k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  467|  1.15k|}
sc_pkcs15_change_pin:
  478|  6.93k|{
  479|  6.93k|	struct sc_context *ctx = p15card->card->ctx;
  480|  6.93k|	struct sc_pin_cmd_data data;
  481|  6.93k|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  482|  6.93k|	struct sc_card *card;
  483|  6.93k|	int r;
  484|       |
  485|  6.93k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  6.93k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.93k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.93k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.93k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.93k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  486|  6.93k|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  6.93k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (486:6): [True: 0, False: 6.93k]
  ------------------
  487|  6.93k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  488|       |
  489|       |	/* make sure the pins are in valid range */
  490|  6.93k|	r = _validate_pin(p15card, auth_info, oldpinlen);
  491|  6.93k|	LOG_TEST_RET(ctx, r, "Old PIN value do not conform PIN policy");
  ------------------
  |  |  174|  6.93k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.93k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.93k|	int _ret = (r); \
  |  |  |  |  168|  6.93k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6.08k, False: 853]
  |  |  |  |  ------------------
  |  |  |  |  169|  6.08k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.08k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  6.08k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  6.08k|		return _ret; \
  |  |  |  |  172|  6.08k|	} \
  |  |  |  |  173|  6.93k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 853]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  492|       |
  493|    853|	r = _validate_pin(p15card, auth_info, newpinlen);
  494|    853|	LOG_TEST_RET(ctx, r, "New PIN value do not conform PIN policy");
  ------------------
  |  |  174|    853|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    853|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    853|	int _ret = (r); \
  |  |  |  |  168|    853|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 420, False: 433]
  |  |  |  |  ------------------
  |  |  |  |  169|    420|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    420|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    420|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    420|		return _ret; \
  |  |  |  |  172|    420|	} \
  |  |  |  |  173|    853|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 433]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  495|       |
  496|    433|	card = p15card->card;
  497|    433|	r = sc_lock(card);
  498|    433|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    433|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    433|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    433|	int _ret = (r); \
  |  |  |  |  168|    433|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 433]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    433|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 433]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  499|       |	/* the path in the pin object is optional */
  500|    433|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (500:6): [True: 164, False: 269]
  |  Branch (500:35): [True: 18, False: 251]
  ------------------
  501|    182|		r = sc_select_file(card, &auth_info->path, NULL);
  502|    182|		if (r)
  ------------------
  |  Branch (502:7): [True: 30, False: 152]
  ------------------
  503|     30|			goto out;
  504|    182|	}
  505|       |
  506|       |	/* set pin_cmd data */
  507|    403|	memset(&data, 0, sizeof(data));
  508|    403|	data.cmd             = SC_PIN_CMD_CHANGE;
  ------------------
  |  |  423|    403|#define SC_PIN_CMD_CHANGE	1
  ------------------
  509|    403|	data.pin_type        = SC_AC_CHV;
  ------------------
  |  |  151|    403|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  510|    403|	data.pin_reference   = auth_info->attrs.pin.reference;
  511|    403|	data.pin1.data       = oldpin;
  512|    403|	data.pin1.len        = oldpinlen;
  513|    403|	data.pin1.pad_char   = auth_info->attrs.pin.pad_char;
  514|    403|	data.pin1.min_length = auth_info->attrs.pin.min_length;
  515|    403|	data.pin1.max_length = auth_info->attrs.pin.max_length;
  516|    403|	data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  517|    403|	data.pin2.data       = newpin;
  518|    403|	data.pin2.len        = newpinlen;
  519|    403|	data.pin2.pad_char   = auth_info->attrs.pin.pad_char;
  520|    403|	data.pin2.min_length = auth_info->attrs.pin.min_length;
  521|    403|	data.pin2.max_length = auth_info->attrs.pin.max_length;
  522|    403|	data.pin2.pad_length = auth_info->attrs.pin.stored_length;
  523|       |
  524|    403|	if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    403|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (524:6): [True: 155, False: 248]
  ------------------
  525|    155|		data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|    155|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  526|       |
  527|    403|	switch (auth_info->attrs.pin.type) {
  ------------------
  |  Branch (527:10): [True: 261, False: 142]
  ------------------
  528|      8|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      8|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (528:2): [True: 8, False: 395]
  ------------------
  529|      8|		data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  433|      8|#define SC_PIN_ENCODING_BCD	1
  ------------------
  530|      8|		data.pin2.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  433|      8|#define SC_PIN_ENCODING_BCD	1
  ------------------
  531|      8|		break;
  532|    253|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    253|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (532:2): [True: 253, False: 150]
  ------------------
  533|    253|		data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|    253|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  534|    253|		data.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|    253|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  535|    253|		break;
  536|    403|	}
  537|       |
  538|    403|	if((!oldpin || !newpin)
  ------------------
  |  Branch (538:6): [True: 0, False: 403]
  |  Branch (538:17): [True: 0, False: 403]
  ------------------
  539|      0|			&& (p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  383|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (539:8): [True: 0, False: 0]
  ------------------
  540|      0|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  567|      0|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (540:8): [True: 0, False: 0]
  ------------------
  541|      0|		data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  542|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (542:7): [True: 0, False: 0]
  ------------------
  543|      0|			data.pin1.prompt = "Please enter SO PIN";
  544|      0|			data.pin2.prompt = "Please enter new SO PIN";
  545|      0|		}
  546|      0|		else {
  547|      0|			data.pin1.prompt = "Please enter PIN";
  548|      0|			data.pin2.prompt = "Please enter new PIN";
  549|      0|		}
  550|      0|	}
  551|       |
  552|    403|	r = sc_pin_cmd(card, &data);
  553|    403|	auth_info->tries_left = data.pin1.tries_left;
  554|    403|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    403|#define SC_SUCCESS				0
  ------------------
  |  Branch (554:6): [True: 78, False: 325]
  ------------------
  555|     78|		sc_pkcs15_pincache_add(p15card, pin_obj, newpin, newpinlen);
  556|       |
  557|    433|out:
  558|    433|	sc_unlock(card);
  559|    433|	return r;
  560|    403|}
sc_pkcs15_unblock_pin:
  569|  6.93k|{
  570|  6.93k|	struct sc_context *ctx = p15card->card->ctx;
  571|  6.93k|	struct sc_pin_cmd_data data;
  572|  6.93k|	struct sc_pkcs15_object *puk_obj;
  573|  6.93k|	struct sc_pkcs15_auth_info *puk_info = NULL;
  574|  6.93k|	int pukref = 0;
  575|  6.93k|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  576|  6.93k|	struct sc_card *card = p15card->card;
  577|  6.93k|	int r;
  578|       |
  579|  6.93k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  6.93k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.93k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.93k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.93k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.93k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|  6.93k|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  6.93k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (580:6): [True: 0, False: 6.93k]
  ------------------
  581|  6.93k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  582|       |
  583|       |	/* make sure the pins are in valid range */
  584|  6.93k|	r = _validate_pin(p15card, auth_info, newpinlen);
  585|  6.93k|	LOG_TEST_RET(ctx, r, "New PIN value do not conform PIN policy");
  ------------------
  |  |  174|  6.93k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.93k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.93k|	int _ret = (r); \
  |  |  |  |  168|  6.93k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6.42k, False: 513]
  |  |  |  |  ------------------
  |  |  |  |  169|  6.42k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  6.42k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  6.42k|		return _ret; \
  |  |  |  |  172|  6.42k|	} \
  |  |  |  |  173|  6.93k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 513]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  586|       |
  587|       |	/* get pin_info object of the puk (this is a little bit complicated
  588|       |	 * as we don't have the id of the puk (at least now))
  589|       |	 * note: for compatibility reasons we give no error if no puk object
  590|       |	 * is found */
  591|       |	/* first step: try to get the pkcs15 object of the puk */
  592|    513|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &pin_obj->auth_id, &puk_obj);
  593|    513|	if (r >= 0 && puk_obj) {
  ------------------
  |  Branch (593:6): [True: 252, False: 261]
  |  Branch (593:16): [True: 252, False: 0]
  ------------------
  594|       |		/* second step:  get the pkcs15 info object of the puk */
  595|    252|		puk_info = (struct sc_pkcs15_auth_info *)puk_obj->data;
  596|    252|		pukref = puk_info->attrs.pin.reference;
  597|    252|	}
  598|       |
  599|    513|	if (!puk_info) {
  ------------------
  |  Branch (599:6): [True: 261, False: 252]
  ------------------
  600|    261|		sc_log(ctx, "Unable to get puk object, using pin object instead!");
  ------------------
  |  |   71|    261|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  601|    261|		puk_info = auth_info;
  602|    261|	}
  603|       |	/* make sure the puk is in valid range */
  604|    513|	r = _validate_pin(p15card, puk_info, puklen);
  605|    513|	LOG_TEST_RET(ctx, r, "PIN do not conforms PIN policy");
  ------------------
  |  |  174|    513|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    513|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    513|	int _ret = (r); \
  |  |  |  |  168|    513|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 166, False: 347]
  |  |  |  |  ------------------
  |  |  |  |  169|    166|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    166|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    166|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    166|		return _ret; \
  |  |  |  |  172|    166|	} \
  |  |  |  |  173|    513|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 347]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  606|       |
  607|       |	/*
  608|       |	 * With the current card driver interface we have no way of specifying different padding
  609|       |	 * flags for the PIN and the PUK. Therefore reject this case.
  610|       |	 */
  611|    347|	if ((auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING) !=
  ------------------
  |  |   59|    347|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (611:6): [True: 0, False: 347]
  ------------------
  612|    347|	    (puk_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)) {
  ------------------
  |  |   59|    347|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  613|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  614|      0|	}
  615|       |
  616|    347|	r = sc_lock(card);
  617|    347|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    347|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    347|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    347|	int _ret = (r); \
  |  |  |  |  168|    347|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 347]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    347|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 347]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  618|       |
  619|       |	/* the path in the pin object is optional */
  620|    347|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (620:6): [True: 156, False: 191]
  |  Branch (620:35): [True: 18, False: 173]
  ------------------
  621|    174|		r = sc_select_file(card, &auth_info->path, NULL);
  622|    174|		if (r)
  ------------------
  |  Branch (622:7): [True: 32, False: 142]
  ------------------
  623|     32|			goto out;
  624|    174|	}
  625|       |
  626|       |	/* set pin_cmd data */
  627|    315|	memset(&data, 0, sizeof(data));
  628|    315|	data.cmd             = SC_PIN_CMD_UNBLOCK;
  ------------------
  |  |  424|    315|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  629|    315|	data.pin_type        = SC_AC_CHV;
  ------------------
  |  |  151|    315|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  630|    315|	data.pin_reference   = auth_info->attrs.pin.reference;
  631|    315|	data.puk_reference   = pukref;
  632|    315|	data.pin1.data       = puk;
  633|    315|	data.pin1.len        = puklen;
  634|    315|	data.pin1.pad_char   = puk_info->attrs.pin.pad_char;
  635|    315|	data.pin1.min_length = puk_info->attrs.pin.min_length;
  636|    315|	data.pin1.max_length = puk_info->attrs.pin.max_length;
  637|    315|	data.pin1.pad_length = puk_info->attrs.pin.stored_length;
  638|    315|	data.pin2.data       = newpin;
  639|    315|	data.pin2.len        = newpinlen;
  640|    315|	data.pin2.pad_char   = auth_info->attrs.pin.pad_char;
  641|    315|	data.pin2.min_length = auth_info->attrs.pin.min_length;
  642|    315|	data.pin2.max_length = auth_info->attrs.pin.max_length;
  643|    315|	data.pin2.pad_length = auth_info->attrs.pin.stored_length;
  644|       |
  645|    315|	if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    315|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (645:6): [True: 148, False: 167]
  ------------------
  646|    148|		data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|    148|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  647|       |
  648|    315|	switch (auth_info->attrs.pin.type) {
  ------------------
  |  Branch (648:10): [True: 176, False: 139]
  ------------------
  649|      6|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      6|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (649:2): [True: 6, False: 309]
  ------------------
  650|      6|		data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  433|      6|#define SC_PIN_ENCODING_BCD	1
  ------------------
  651|      6|		break;
  652|    170|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    170|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (652:2): [True: 170, False: 145]
  ------------------
  653|    170|		data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|    170|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  654|    170|		break;
  655|    315|	}
  656|       |
  657|    315|	switch (puk_info->attrs.pin.type) {
  ------------------
  |  Branch (657:10): [True: 172, False: 143]
  ------------------
  658|      6|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      6|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (658:2): [True: 6, False: 309]
  ------------------
  659|      6|		data.pin2.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  433|      6|#define SC_PIN_ENCODING_BCD	1
  ------------------
  660|      6|		break;
  661|    166|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    166|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (661:2): [True: 166, False: 149]
  ------------------
  662|    166|		data.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|    166|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  663|    166|		break;
  664|    315|	}
  665|       |
  666|    315|	if((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  383|    630|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (666:6): [True: 0, False: 315]
  ------------------
  667|    315|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  567|    315|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (667:8): [True: 0, False: 315]
  ------------------
  668|      0|		data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  669|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (669:7): [True: 0, False: 0]
  ------------------
  670|      0|			data.pin1.prompt = "Please enter PUK";
  671|      0|			data.pin2.prompt = "Please enter new SO PIN";
  672|      0|		}
  673|      0|		else {
  674|      0|			data.pin1.prompt = "Please enter PUK";
  675|      0|			data.pin2.prompt = "Please enter new PIN";
  676|      0|		}
  677|      0|	}
  678|       |
  679|    315|	r = sc_pin_cmd(card, &data);
  680|    315|	auth_info->tries_left = data.pin1.tries_left;
  681|    315|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    315|#define SC_SUCCESS				0
  ------------------
  |  Branch (681:6): [True: 74, False: 241]
  ------------------
  682|     74|		sc_pkcs15_pincache_add(p15card, pin_obj, newpin, newpinlen);
  683|       |
  684|    347|out:
  685|    347|	sc_unlock(card);
  686|    347|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    347|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    347|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    347|	int _ret = r; \
  |  |  |  |  155|    347|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 347, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    347|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    273|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 273, False: 74]
  |  |  |  |  ------------------
  |  |  |  |  157|    347|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    347|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    347|	return _ret; \
  |  |  |  |  163|    347|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|    347|}
sc_pkcs15_get_pin_info:
  691|  6.93k|{
  692|  6.93k|	int r;
  693|  6.93k|	struct sc_pin_cmd_data data;
  694|  6.93k|	struct sc_card *card = p15card->card;
  695|  6.93k|	struct sc_context *ctx = card->ctx;
  696|  6.93k|	struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *) pin_obj->data;
  697|       |
  698|  6.93k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  6.93k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.93k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.93k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.93k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.93k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  699|       |
  700|  6.93k|	r = sc_lock(card);
  701|  6.93k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  6.93k|#define SC_SUCCESS				0
  ------------------
  |  Branch (701:6): [True: 0, False: 6.93k]
  ------------------
  702|      0|		return r;
  703|       |
  704|  6.93k|	if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|  6.93k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (704:6): [True: 0, False: 6.93k]
  ------------------
  705|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  706|      0|		goto out;
  707|      0|	}
  708|       |
  709|       |	/* the path in the pin object is optional */
  710|  6.93k|	if ((pin_info->path.len > 0) || ((pin_info->path.aid.len > 0))) {
  ------------------
  |  Branch (710:6): [True: 925, False: 6.01k]
  |  Branch (710:34): [True: 373, False: 5.64k]
  ------------------
  711|  1.29k|		r = sc_select_file(card, &pin_info->path, NULL);
  712|  1.29k|		if (r)
  ------------------
  |  Branch (712:7): [True: 542, False: 756]
  ------------------
  713|    542|			goto out;
  714|  1.29k|	}
  715|       |
  716|       |	/* Try to update PIN info from card */
  717|  6.39k|	memset(&data, 0, sizeof(data));
  718|  6.39k|	data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  425|  6.39k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  719|  6.39k|	data.pin_type = pin_info->auth_method;
  720|  6.39k|	data.pin_reference = pin_info->attrs.pin.reference;
  721|       |
  722|  6.39k|	r = sc_pin_cmd(card, &data);
  723|  6.39k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  6.39k|#define SC_SUCCESS				0
  ------------------
  |  Branch (723:6): [True: 1.17k, False: 5.22k]
  ------------------
  724|  1.17k|		if (data.pin1.max_tries > 0)
  ------------------
  |  Branch (724:7): [True: 6, False: 1.16k]
  ------------------
  725|      6|			pin_info->max_tries = data.pin1.max_tries;
  726|  1.17k|		pin_info->tries_left = data.pin1.tries_left;
  727|  1.17k|		pin_info->logged_in = data.pin1.logged_in;
  728|  1.17k|	}
  729|       |
  730|  6.93k|out:
  731|  6.93k|	sc_unlock(card);
  732|  6.93k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  6.93k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.93k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.93k|	int _ret = r; \
  |  |  |  |  155|  6.93k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.93k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.93k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.76k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.76k, False: 1.17k]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.93k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.93k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  6.93k|	return _ret; \
  |  |  |  |  163|  6.93k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  733|  6.93k|}
sc_pkcs15_free_auth_info:
  737|  7.48k|{
  738|  7.48k|	free(auth_info);
  739|  7.48k|}
sc_pkcs15_pincache_add:
  745|    924|{
  746|    924|	struct sc_context *ctx = p15card->card->ctx;
  747|    924|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  748|    924|	struct sc_pkcs15_object *obj = NULL;
  749|    924|	int r;
  750|       |
  751|    924|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    924|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    924|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    924|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    924|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 924]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  752|       |
  753|    924|	if (!pin || !pinlen)   {
  ------------------
  |  Branch (753:6): [True: 0, False: 924]
  |  Branch (753:14): [True: 0, False: 924]
  ------------------
  754|      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__
  |  |  ------------------
  ------------------
  755|      0|		return;
  756|      0|	}
  757|    924|	else if (!p15card->opts.use_pin_cache)   {
  ------------------
  |  Branch (757:11): [True: 12, False: 912]
  ------------------
  758|     12|		sc_log(ctx, "PIN caching not enabled");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  759|     12|		return;
  760|     12|	}
  761|    912|	else if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    912|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (761:11): [True: 0, False: 912]
  ------------------
  762|      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__
  |  |  ------------------
  ------------------
  763|      0|		return;
  764|      0|	}
  765|       |
  766|       |	/* If the PIN protects an object with user consent, don't cache it */
  767|       |
  768|    912|	obj = p15card->obj_list;
  769|  6.71k|	while (obj != NULL) {
  ------------------
  |  Branch (769:9): [True: 5.81k, False: 902]
  ------------------
  770|       |		/* Compare 'sc_pkcs15_object.auth_id' with 'sc_pkcs15_pin_info.auth_id'.
  771|       |		 * In accordance with PKCS#15 "6.1.8 CommonObjectAttributes" and
  772|       |		 * "6.1.16 CommonAuthenticationObjectAttributes" with the exception that
  773|       |		 * "CommonObjectAttributes.accessControlRules" are not taken into account. */
  774|       |
  775|  5.81k|		if (sc_pkcs15_compare_id(&obj->auth_id, &auth_info->auth_id)) {
  ------------------
  |  Branch (775:7): [True: 1.22k, False: 4.58k]
  ------------------
  776|       |			/* Caching is refused, if the protected object requires user consent */
  777|  1.22k|			if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (777:8): [True: 1.22k, False: 0]
  ------------------
  778|  1.22k|				if (obj->user_consent > 0) {
  ------------------
  |  Branch (778:9): [True: 10, False: 1.21k]
  ------------------
  779|     10|					sc_log(ctx, "caching refused (user consent)");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  780|     10|					return;
  781|     10|				}
  782|  1.22k|			}
  783|  1.22k|		}
  784|       |
  785|  5.80k|		obj = obj->next;
  786|  5.80k|	}
  787|       |
  788|    902|	r = sc_pkcs15_allocate_object_content(ctx, pin_obj, pin, pinlen);
  789|    902|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|    902|#define SC_SUCCESS				0
  ------------------
  |  Branch (789:6): [True: 0, False: 902]
  ------------------
  790|      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__
  |  |  ------------------
  ------------------
  791|      0|		return;
  792|      0|	}
  793|       |
  794|    902|	pin_obj->usage_counter = 0;
  795|    902|	sc_log(ctx, "PIN(%s) cached", pin_obj->label);
  ------------------
  |  |   71|    902|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  796|    902|}
sc_pkcs15_pincache_revalidate:
  801|    381|{
  802|    381|	struct sc_context *ctx = p15card->card->ctx;
  803|    381|	sc_pkcs15_object_t *pin_obj;
  804|    381|	int r;
  805|       |
  806|    381|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    381|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  807|    381|	if (!p15card->opts.use_pin_cache)
  ------------------
  |  Branch (807:6): [True: 10, False: 371]
  ------------------
  808|     10|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     10|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  809|       |
  810|       |	/*  Apps that do not support CK_ALWAYS_AUTHENTICATE
  811|       |	 *  may need pin_cache_ignore_user_consent = 1 */
  812|    371|	if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (812:6): [True: 371, False: 0]
  ------------------
  813|    371|	    if (obj->user_consent)
  ------------------
  |  Branch (813:10): [True: 17, False: 354]
  ------------------
  814|     17|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     17|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  815|    371|	}
  816|       |
  817|    354|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  383|    708|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (817:7): [True: 0, False: 354]
  ------------------
  818|    354|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH))
  ------------------
  |  |  567|    354|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (818:8): [True: 0, False: 354]
  ------------------
  819|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  820|       |
  821|    354|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &obj->auth_id, &pin_obj);
  822|    354|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    354|#define SC_SUCCESS				0
  ------------------
  |  Branch (822:6): [True: 17, False: 337]
  ------------------
  823|     17|		sc_log(ctx, "Could not find pin object for auth_id %s", sc_pkcs15_print_id(&obj->auth_id));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  824|     17|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     17|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  825|     17|	}
  826|       |
  827|    337|	if (pin_obj->usage_counter >= p15card->opts.pin_cache_counter) {
  ------------------
  |  Branch (827:6): [True: 0, False: 337]
  ------------------
  828|      0|		sc_pkcs15_free_object_content(pin_obj);
  829|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  830|      0|	}
  831|       |
  832|    337|	if (!pin_obj->content.value || !pin_obj->content.len)
  ------------------
  |  Branch (832:6): [True: 33, False: 304]
  |  Branch (832:33): [True: 0, False: 304]
  ------------------
  833|     33|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     33|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  834|       |
  835|    304|	pin_obj->usage_counter++;
  836|    304|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pin_obj->content.value, pin_obj->content.len);
  837|    304|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    304|#define SC_SUCCESS				0
  ------------------
  |  Branch (837:6): [True: 28, False: 276]
  ------------------
  838|       |		/* Ensure that wrong PIN isn't used again */
  839|     28|		sc_pkcs15_free_object_content(pin_obj);
  840|       |
  841|     28|		sc_log(ctx, "Verify PIN error %i", r);
  ------------------
  |  |   71|     28|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  842|     28|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     28|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  843|     28|	}
  844|       |
  845|    276|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    276|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    276|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    276|	int _ret = r; \
  |  |  |  |  155|    276|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 276, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    276|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 276]
  |  |  |  |  ------------------
  |  |  |  |  157|    276|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    276|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    276|	return _ret; \
  |  |  |  |  163|    276|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  846|    276|}
pkcs15-pin.c:_validate_pin:
  261|  22.1k|{
  262|  22.1k|	size_t max_length;
  263|  22.1k|	if (p15card == NULL) {
  ------------------
  |  Branch (263:6): [True: 0, False: 22.1k]
  ------------------
  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|  22.1k|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  22.1k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (268:6): [True: 0, False: 22.1k]
  ------------------
  269|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  270|       |
  271|       |	/* prevent buffer overflow from hostile card */
  272|  22.1k|	if (auth_info->attrs.pin.stored_length > SC_MAX_PIN_SIZE)
  ------------------
  |  |   40|  22.1k|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (272:6): [True: 0, False: 22.1k]
  ------------------
  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|  22.1k|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  383|  44.3k|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (276:7): [True: 0, False: 22.1k]
  ------------------
  277|  22.1k|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  567|  22.1k|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (277:8): [True: 0, False: 22.1k]
  ------------------
  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|  22.1k|	max_length = auth_info->attrs.pin.max_length != 0 ? auth_info->attrs.pin.max_length : SC_MAX_PIN_SIZE;
  ------------------
  |  |   40|  22.8k|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (282:15): [True: 21.4k, False: 703]
  ------------------
  283|  22.1k|	if (pinlen > max_length || pinlen < auth_info->attrs.pin.min_length)
  ------------------
  |  Branch (283:6): [True: 1.82k, False: 20.3k]
  |  Branch (283:29): [True: 17.3k, False: 2.99k]
  ------------------
  284|  19.1k|		return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|  19.1k|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  285|       |
  286|  2.99k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.99k|#define SC_SUCCESS				0
  ------------------
  287|  22.1k|}

sc_pkcs15emu_piv_init_ex:
 1278|  12.5k|{
 1279|  12.5k|	sc_card_t   *card = p15card->card;
 1280|  12.5k|	sc_context_t    *ctx = card->ctx;
 1281|       |
 1282|  12.5k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1283|       |
 1284|  12.5k|	if (piv_detect_card(p15card))
  ------------------
  |  Branch (1284:6): [True: 11.5k, False: 957]
  ------------------
 1285|  11.5k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.5k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1286|    957|	return sc_pkcs15emu_piv_init(p15card);
 1287|  12.5k|}
pkcs15-piv.c:piv_detect_card:
  237|  12.5k|{
  238|  12.5k|	sc_card_t *card = p15card->card;
  239|       |
  240|  12.5k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  241|  12.5k|	if (card->type < SC_CARD_TYPE_PIV_II_BASE
  ------------------
  |  Branch (241:6): [True: 4.71k, False: 7.80k]
  ------------------
  242|  7.80k|		|| card->type >= SC_CARD_TYPE_PIV_II_BASE + 1000)
  ------------------
  |  Branch (242:6): [True: 6.85k, False: 957]
  ------------------
  243|  11.5k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  11.5k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  244|    957|	return SC_SUCCESS;
  ------------------
  |  |   28|    957|#define SC_SUCCESS				0
  ------------------
  245|  12.5k|}
pkcs15-piv.c:sc_pkcs15emu_piv_init:
  249|    957|{
  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|    957|	static const objdata objects[] = {
  256|    957|	{"01", "Card Capability Container",
  257|    957|			"2.16.840.1.101.3.7.1.219.0", NULL, "DB00", 0},
  258|    957|	{"02", "Card Holder Unique Identifier",
  259|    957|			"2.16.840.1.101.3.7.2.48.0", NULL, "3000", 0},
  260|    957|	{"03", "Unsigned Card Holder Unique Identifier",
  261|    957|			"2.16.840.1.101.3.7.2.48.2", NULL, "3010", 0},
  262|    957|	{"04", "X.509 Certificate for PIV Authentication",
  263|    957|			"2.16.840.1.101.3.7.2.1.1", NULL, "0101", 0},
  264|    957|	{"05", "Cardholder Fingerprints",
  265|    957|			"2.16.840.1.101.3.7.2.96.16", "01", "6010", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  266|    957|	{"06", "Printed Information",
  267|    957|			"2.16.840.1.101.3.7.2.48.1", "01", "3001", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  268|    957|	{"07", "Cardholder Facial Image",
  269|    957|			"2.16.840.1.101.3.7.2.96.48", "01", "6030", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  270|    957|	{"08", "X.509 Certificate for Digital Signature",
  271|    957|			"2.16.840.1.101.3.7.2.1.0",  NULL, "0100", 0},
  272|    957|	{"09", "X.509 Certificate for Key Management",
  273|    957|			"2.16.840.1.101.3.7.2.1.2", NULL, "0102", 0},
  274|    957|	{"10","X.509 Certificate for Card Authentication",
  275|    957|			"2.16.840.1.101.3.7.2.5.0", NULL, "0500", 0},
  276|    957|	{"11", "Security Object",
  277|    957|			"2.16.840.1.101.3.7.2.144.0", NULL, "9000", 0},
  278|    957|	{"12", "Discovery Object",
  279|    957|			"2.16.840.1.101.3.7.2.96.80", NULL, "6050", 0},
  280|    957|	{"13", "Key History Object",
  281|    957|			"2.16.840.1.101.3.7.2.96.96", NULL, "6060", 0},
  282|    957|	{"14", "Cardholder Iris Image",
  283|    957|			"2.16.840.1.101.3.7.2.16.21", NULL, "1015", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  284|       |
  285|    957|	{"15", "Retired X.509 Certificate for Key Management 1",
  286|    957|			"2.16.840.1.101.3.7.2.16.1", NULL, "1001", 0},
  287|    957|	{"16", "Retired X.509 Certificate for Key Management 2",
  288|    957|			"2.16.840.1.101.3.7.2.16.2", NULL, "1002", 0},
  289|    957|	{"17", "Retired X.509 Certificate for Key Management 3",
  290|    957|			"2.16.840.1.101.3.7.2.16.3", NULL, "1003", 0},
  291|    957|	{"18", "Retired X.509 Certificate for Key Management 4",
  292|    957|			"2.16.840.1.101.3.7.2.16.4", NULL, "1004", 0},
  293|    957|	{"19", "Retired X.509 Certificate for Key Management 5",
  294|    957|			"2.16.840.1.101.3.7.2.16.5", NULL, "1005", 0},
  295|    957|	{"20", "Retired X.509 Certificate for Key Management 6",
  296|    957|			"2.16.840.1.101.3.7.2.16.6", NULL, "1006", 0},
  297|    957|	{"21", "Retired X.509 Certificate for Key Management 7",
  298|    957|			"2.16.840.1.101.3.7.2.16.7", NULL, "1007", 0},
  299|    957|	{"22", "Retired X.509 Certificate for Key Management 8",
  300|    957|			"2.16.840.1.101.3.7.2.16.8", NULL, "1008", 0},
  301|    957|	{"23", "Retired X.509 Certificate for Key Management 9",
  302|    957|			"2.16.840.1.101.3.7.2.16.9", NULL, "1009", 0},
  303|    957|	{"24", "Retired X.509 Certificate for Key Management 10",
  304|    957|			"2.16.840.1.101.3.7.2.16.10", NULL, "100A", 0},
  305|    957|	{"25", "Retired X.509 Certificate for Key Management 11",
  306|    957|			"2.16.840.1.101.3.7.2.16.11", NULL, "100B", 0},
  307|    957|	{"26", "Retired X.509 Certificate for Key Management 12",
  308|    957|			"2.16.840.1.101.3.7.2.16.12", NULL, "100C", 0},
  309|    957|	{"27", "Retired X.509 Certificate for Key Management 13",
  310|    957|			"2.16.840.1.101.3.7.2.16.13", NULL, "100D", 0},
  311|    957|	{"28", "Retired X.509 Certificate for Key Management 14",
  312|    957|			"2.16.840.1.101.3.7.2.16.14", NULL, "100E", 0},
  313|    957|	{"29", "Retired X.509 Certificate for Key Management 15",
  314|    957|			"2.16.840.1.101.3.7.2.16.15", NULL, "100F", 0},
  315|    957|	{"30", "Retired X.509 Certificate for Key Management 16",
  316|    957|			"2.16.840.1.101.3.7.2.16.16", NULL, "1010", 0},
  317|    957|	{"31", "Retired X.509 Certificate for Key Management 17",
  318|    957|			"2.16.840.1.101.3.7.2.16.17", NULL, "1011", 0},
  319|    957|	{"32", "Retired X.509 Certificate for Key Management 18",
  320|    957|			"2.16.840.1.101.3.7.2.16.18", NULL, "1012", 0},
  321|    957|	{"33", "Retired X.509 Certificate for Key Management 19",
  322|    957|			"2.16.840.1.101.3.7.2.16.19", NULL, "1013", 0},
  323|    957|	{"34", "Retired X.509 Certificate for Key Management 20",
  324|    957|			"2.16.840.1.101.3.7.2.16.20", NULL, "1014", 0},
  325|       |	/* new in 800-73-4 */
  326|    957|	{"35", "Biometric Information Templates Group Template",
  327|    957|			"2.16.840.1.101.3.7.2.16.22", NULL, "1016", 0},
  328|    957|	{"36", "Secure Messaging Certificate Signer",
  329|    957|			"2.16.840.1.101.3.7.2.16.23", NULL, "1017", 0},
  330|    957|	{"37", "Pairing Code Reference Data Container",
  331|    957|			"2.16.840.1.101.3.7.2.16.24", NULL, "1018", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  332|    957|	{NULL, NULL, NULL, NULL, NULL, 0}
  333|    957|	};
  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|    957|#define PIV_NUM_CERTS 25
  346|    957|#define PIV_NUM_KEYS  24
  347|       |
  348|       |	// clang-format off
  349|    957|	static const cdata certs[PIV_NUM_CERTS] = {
  350|    957|		{"01", "Certificate for PIV Authentication", "0101cece", 0, 0},
  351|    957|		{"02", "Certificate for Digital Signature", "0100cece", 0, 0},
  352|    957|		{"03", "Certificate for Key Management", "0102cece", 0, 0},
  353|    957|		{"04", "Certificate for Card Authentication", "0500cece", 0, 0},
  354|    957|		{"05", "Retired Certificate for Key Management 1", "1001cece", 0, 0},
  355|    957|		{"06", "Retired Certificate for Key Management 2", "1002cece", 0, 0},
  356|    957|		{"07", "Retired Certificate for Key Management 3", "1003cece", 0, 0},
  357|    957|		{"08", "Retired Certificate for Key Management 4", "1004cece", 0, 0},
  358|    957|		{"09", "Retired Certificate for Key Management 5", "1005cece", 0, 0},
  359|    957|		{"10", "Retired Certificate for Key Management 6", "1006cece", 0, 0},
  360|    957|		{"11", "Retired Certificate for Key Management 7", "1007cece", 0, 0},
  361|    957|		{"12", "Retired Certificate for Key Management 8", "1008cece", 0, 0},
  362|    957|		{"13", "Retired Certificate for Key Management 9", "1009cece", 0, 0},
  363|    957|		{"14", "Retired Certificate for Key Management 10", "100Acece", 0, 0},
  364|    957|		{"15", "Retired Certificate for Key Management 11", "100Bcece", 0, 0},
  365|    957|		{"16", "Retired Certificate for Key Management 12", "100Ccece", 0, 0},
  366|    957|		{"17", "Retired Certificate for Key Management 13", "100Dcece", 0, 0},
  367|    957|		{"18", "Retired Certificate for Key Management 14", "100Ecece", 0, 0},
  368|    957|		{"19", "Retired Certificate for Key Management 15", "100Fcece", 0, 0},
  369|    957|		{"20", "Retired Certificate for Key Management 16", "1010cece", 0, 0},
  370|    957|		{"21", "Retired Certificate for Key Management 17", "1011cece", 0, 0},
  371|    957|		{"22", "Retired Certificate for Key Management 18", "1012cece", 0, 0},
  372|    957|		{"23", "Retired Certificate for Key Management 19", "1013cece", 0, 0},
  373|    957|		{"24", "Retired Certificate for Key Management 20", "1014cece", 0, 0},
  374|       |		/* Yubikey Attestation uses "25" but not read via GET_DATA */
  375|    957|		{"81", "Secure Messaging Certificate Signer",   "1017cece", 0, 0} /* no keys on card */
  376|    957|	};
  377|       |	// clang-format on
  378|       |
  379|       |	// clang-format off
  380|    957|	static const pindata pins[] = {
  381|    957|		{ "01", "PIN", "", 0x80,
  382|       |		  /* label, flag  and ref will change if using global pin */
  383|    957|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    957|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  384|    957|		  8, 4, 8,
  385|    957|		  SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|    957|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  386|    957|		  SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    957|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  387|    957|		  SC_PKCS15_PIN_FLAG_LOCAL,
  ------------------
  |  |   55|    957|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  388|    957|		  -1, 0xFF,
  389|    957|		  SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  390|       |
  391|    957|		{ "02", "PIV PUK", "", 0x81,
  392|    957|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    957|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  393|    957|		  8, 4, 8,
  394|    957|		  SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|    957|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  395|    957|		  SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    957|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  396|    957|		  SC_PKCS15_PIN_FLAG_SO_PIN |
  ------------------
  |  |   61|    957|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  397|    957|		  SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN,
  ------------------
  |  |   60|    957|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
  398|    957|		  -1, 0xFF,
  399|    957|		  SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  400|       |
  401|       |		/* only used with minidriver */
  402|    957|		{ "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|    957|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|    957|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  406|    957|		  8, 4, 8,
  407|    957|		  SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|    957|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  408|    957|		  SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    957|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  409|    957|		  SC_PKCS15_PIN_FLAG_LOCAL,
  ------------------
  |  |   55|    957|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  410|    957|		  -1, 0xFF,
  411|    957|		  SC_PKCS15_CO_FLAG_PRIVATE, 1}, /* only use if cardmod */
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  412|    957|		{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  413|    957|	};
  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|    957|	static const pubdata pubkeys[PIV_NUM_KEYS] = {
  426|    957|		{ "01", "PIV AUTH pubkey",
  427|    957|			 	/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT |
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  428|    957|			 		SC_PKCS15_PRKEY_USAGE_WRAP |
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  429|    957|					SC_PKCS15_PRKEY_USAGE_VERIFY |
  ------------------
  |  |  311|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  430|    957|					SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER,
  ------------------
  |  |  312|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  431|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_VERIFY,
  ------------------
  |  |  311|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  432|    957|			"9A06", 0x9A, NULL, 0, "PIV_9A_KEY"},
  433|    957|		{ "02", "SIGN pubkey",
  434|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT |
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  435|    957|					SC_PKCS15_PRKEY_USAGE_VERIFY |
  ------------------
  |  |  311|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  436|    957|					SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER |
  ------------------
  |  |  312|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  437|    957|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
  ------------------
  |  |  314|    957|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  438|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_VERIFY |
  ------------------
  |  |  311|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  439|    957|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
  ------------------
  |  |  314|    957|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  440|    957|			"9C06", 0x9C, NULL, 0, "PIV_9C_KEY"},
  441|    957|		{ "03", "KEY MAN pubkey",
  442|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT| SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT| SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  443|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  444|    957|			"9D06", 0x9D, NULL, 0, "PIV_9D_KEY"},
  445|    957|		{ "04", "CARD AUTH pubkey",
  446|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_VERIFY |
  ------------------
  |  |  311|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  447|    957|					SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER,
  ------------------
  |  |  312|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  448|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_VERIFY,
  ------------------
  |  |  311|    957|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  449|    957|			"9E06", 0x9E, NULL, 0, "PIV_9E_KEY"},  /* no pin, and avail in contactless */
  450|       |
  451|    957|		{ "05", "Retired KEY MAN 1",
  452|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  453|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  454|    957|			 "8206", 0x82, NULL, 0, "PIV_82_KEY"},
  455|    957|		{ "06", "Retired KEY MAN 2",
  456|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  457|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  458|    957|			 "8306", 0x83, NULL, 0, "PIV_83_KEY"},
  459|    957|		{ "07", "Retired KEY MAN 3",
  460|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  461|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  462|    957|			 "8406", 0x84, NULL, 0, "PIV_84_KEY"},
  463|    957|		{ "08", "Retired KEY MAN 4",
  464|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  465|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  466|    957|			 "8506", 0x85, NULL, 0, "PIV_85_KEY"},
  467|    957|		{ "09", "Retired KEY MAN 5",
  468|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  469|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  470|    957|			 "8606", 0x86, NULL, 0, "PIV_86_KEY"},
  471|    957|		{ "10", "Retired KEY MAN 6",
  472|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  473|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  474|    957|			 "8706", 0x87, NULL, 0, "PIV_87_KEY"},
  475|    957|		{ "11", "Retired KEY MAN 7",
  476|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  477|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  478|    957|			 "8806", 0x88, NULL, 0, "PIV_88_KEY"},
  479|    957|		{ "12", "Retired KEY MAN 8",
  480|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  481|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  482|    957|			 "8906", 0x89, NULL, 0, "PIV_89_KEY"},
  483|    957|		{ "13", "Retired KEY MAN 9",
  484|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  485|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  486|    957|			 "8A06", 0x8A, NULL, 0, "PIV_8A_KEY"},
  487|    957|		{ "14", "Retired KEY MAN 10",
  488|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  489|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  490|    957|			 "8B06", 0x8B, NULL, 0, "PIV_8B_KEY"},
  491|    957|		{ "15", "Retired KEY MAN 11",
  492|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  493|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  494|    957|			 "8C06", 0x8C, NULL, 0, "PIV_8C_KEY"},
  495|    957|		{ "16", "Retired KEY MAN 12",
  496|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  497|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  498|    957|			 "8D06", 0x8D, NULL, 0, "PIV_8D_KEY"},
  499|    957|		{ "17", "Retired KEY MAN 13",
  500|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  501|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  502|    957|			 "8E06", 0x8E, NULL, 0, "PIV_8E_KEY"},
  503|    957|		{ "18", "Retired KEY MAN 14",
  504|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  505|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  506|    957|			 "8F06", 0x8F, NULL, 0, "PIV_8F_KEY"},
  507|    957|		{ "19", "Retired KEY MAN 15",
  508|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  509|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  510|    957|			 "9006", 0x90, NULL, 0, "PIV_90_KEY"},
  511|    957|		{ "20", "Retired KEY MAN 16",
  512|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  513|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  514|    957|			 "9106", 0x91, NULL, 0, "PIV_91_KEY"},
  515|    957|		{ "21", "Retired KEY MAN 17",
  516|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  517|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  518|    957|			 "9206", 0x92, NULL, 0, "PIV_92_KEY"},
  519|    957|		{ "22", "Retired KEY MAN 18",
  520|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  521|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  522|    957|			 "9306", 0x93, NULL, 0, "PIV_93_KEY"},
  523|    957|		{ "23", "Retired KEY MAN 19",
  524|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  525|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  526|    957|			 "9406", 0x94, NULL, 0, "PIV_94_KEY"},
  527|    957|		{ "24", "Retired KEY MAN 20",
  528|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  305|    957|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_WRAP,
  ------------------
  |  |  309|    957|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  529|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  530|    957|			 "9506", 0x95, NULL, 0, "PIV_95_KEY"}
  531|    957|	};
  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|    957|	static const prdata prkeys[PIV_NUM_KEYS] = {
  543|    957|		{ "01", "PIV AUTH key",
  544|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT |
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  545|    957|					SC_PKCS15_PRKEY_USAGE_UNWRAP |
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  546|    957|					SC_PKCS15_PRKEY_USAGE_SIGN |
  ------------------
  |  |  307|    957|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  547|    957|					SC_PKCS15_PRKEY_USAGE_SIGNRECOVER,
  ------------------
  |  |  308|    957|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  548|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|    957|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  549|    957|			"", 0x9A, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  550|    957|		{ "02", "SIGN key",
  551|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT |
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  552|    957|					SC_PKCS15_PRKEY_USAGE_SIGN |
  ------------------
  |  |  307|    957|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  553|    957|					SC_PKCS15_PRKEY_USAGE_SIGNRECOVER |
  ------------------
  |  |  308|    957|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  554|    957|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
  ------------------
  |  |  314|    957|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  555|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_SIGN |
  ------------------
  |  |  307|    957|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  556|    957|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION,
  ------------------
  |  |  314|    957|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  557|    957|			"", 0x9C, "01", SC_PKCS15_CO_FLAG_PRIVATE, 1}, /* use sign pin and user_consent */
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  558|    957|		{ "03", "KEY MAN key",
  559|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  560|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  561|    957|			"", 0x9D, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  562|    957|		{ "04", "CARD AUTH key",
  563|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_SIGN |
  ------------------
  |  |  307|    957|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  564|    957|				SC_PKCS15_PRKEY_USAGE_SIGNRECOVER,
  ------------------
  |  |  308|    957|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  565|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|    957|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  566|    957|			"", 0x9E, NULL, 0, 0}, /* no PIN needed, works with wireless */
  567|    957|		{ "05", "Retired KEY MAN 1",
  568|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  569|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  570|    957|			"", 0x82, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  571|    957|		{ "06", "Retired KEY MAN 2",
  572|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  573|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  574|    957|			"", 0x83, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  575|    957|		{ "07", "Retired KEY MAN 3",
  576|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  577|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  578|    957|			"", 0x84, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  579|    957|		{ "08", "Retired KEY MAN 4",
  580|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  581|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  582|    957|			"", 0x85, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  583|    957|		{ "09", "Retired KEY MAN 5",
  584|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  585|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  586|    957|			"", 0x86, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  587|    957|		{ "10", "Retired KEY MAN 6",
  588|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  589|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  590|    957|			"", 0x87, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  591|    957|		{ "11", "Retired KEY MAN 7",
  592|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  593|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  594|    957|			"", 0x88, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  595|    957|		{ "12", "Retired KEY MAN 8",
  596|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  597|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  598|    957|			"", 0x89, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  599|    957|		{ "13", "Retired KEY MAN 9",
  600|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  601|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  602|    957|			"", 0x8A, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  603|    957|		{ "14", "Retired KEY MAN 10",
  604|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  605|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  606|    957|			"", 0x8B, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  607|    957|		{ "15", "Retired KEY MAN 11",
  608|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  609|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  610|    957|			"", 0x8C, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  611|    957|		{ "16", "Retired KEY MAN 12",
  612|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  613|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  614|    957|			"", 0x8D, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  615|    957|		{ "17", "Retired KEY MAN 13",
  616|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  617|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  618|    957|			"", 0x8E, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  619|    957|		{ "18", "Retired KEY MAN 14",
  620|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  621|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  622|    957|			"", 0x8F, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  623|    957|		{ "19", "Retired KEY MAN 15",
  624|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  625|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  626|    957|			"", 0x90, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  627|    957|		{ "20", "Retired KEY MAN 16",
  628|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  629|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  630|    957|			"", 0x91, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  631|    957|		{ "21", "Retired KEY MAN 17",
  632|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  633|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  634|    957|			"", 0x92, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  635|    957|		{ "22", "Retired KEY MAN 18",
  636|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  637|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  638|    957|			"", 0x93, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  639|    957|		{ "23", "Retired KEY MAN 19",
  640|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  641|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  642|    957|			"", 0x94, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0},
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  643|    957|		{ "24", "Retired KEY MAN 20",
  644|    957|				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  306|    957|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              				/*RSA*/SC_PKCS15_PRKEY_USAGE_DECRYPT | SC_PKCS15_PRKEY_USAGE_UNWRAP,
  ------------------
  |  |  310|    957|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  645|    957|				/*EC*/SC_PKCS15_PRKEY_USAGE_DERIVE,
  ------------------
  |  |  313|    957|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  646|    957|			"", 0x95, "01", SC_PKCS15_CO_FLAG_PRIVATE, 0}
  ------------------
  |  |   50|    957|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  647|       |		/* SM Signer certificate does not have private key on card */
  648|    957|	};
  649|       |	// clang-format on
  650|       |
  651|    957|	int    r, i;
  652|    957|	sc_card_t *card = p15card->card;
  653|    957|	sc_serial_number_t serial;
  654|    957|	char buf[SC_MAX_SERIALNR * 2 + 1];
  655|    957|	common_key_info ckis[PIV_NUM_CERTS];
  656|    957|	int follows_nist_fascn = 0;
  657|    957|	char *token_name = NULL;
  658|       |
  659|    957|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    957|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    957|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    957|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 957]
  |  |  ------------------
  ------------------
  660|       |
  661|    957|	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|    957|	set_string(&p15card->tokeninfo->label, "PIV_II");
  667|    957|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   42|    957|#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|    957|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  677|    957|	if (r < 0) {
  ------------------
  |  Branch (677:6): [True: 916, False: 41]
  ------------------
  678|    916|		sc_log(card->ctx, "sc_card_ctl rc=%d",r);
  ------------------
  |  |   71|    916|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  679|    916|		set_string(&p15card->tokeninfo->serial_number, "00000000");
  680|    916|	} else {
  681|     41|		sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
  682|     41|		set_string(&p15card->tokeninfo->serial_number, buf);
  683|     41|	}
  684|       |	/* US gov issued PIVs have CHUID with a FASCN that does not start with 9999 */
  685|    957|	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: 39, False: 918]
  |  Branch (685:28): [True: 7, False: 32]
  |  Branch (685:55): [True: 5, False: 2]
  |  Branch (685:82): [True: 3, False: 2]
  |  Branch (685:109): [True: 1, False: 2]
  ------------------
  686|     38|	    follows_nist_fascn = 1;
  687|     38|	}
  688|       |
  689|    957|	sc_log(card->ctx,  "PIV-II adding objects...");
  ------------------
  |  |   71|    957|#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|  36.3k|	for (i = 0; objects[i].label; i++) {
  ------------------
  |  Branch (692:14): [True: 35.4k, False: 957]
  ------------------
  693|  35.4k|		struct sc_pkcs15_data_info obj_info;
  694|  35.4k|		struct sc_pkcs15_object    obj_obj;
  695|       |
  696|  35.4k|		memset(&obj_info, 0, sizeof(obj_info));
  697|  35.4k|		memset(&obj_obj, 0, sizeof(obj_obj));
  698|  35.4k|		sc_pkcs15_format_id(objects[i].id, &obj_info.id);
  699|  35.4k|		sc_format_path(objects[i].path, &obj_info.path);
  700|       |
  701|       |		/* See if the object can not be present on the card */
  702|  35.4k|		r = sc_card_ctl(card, SC_CARDCTL_PIV_OBJECT_PRESENT, &obj_info.path);
  703|  35.4k|		if (r == 1)
  ------------------
  |  Branch (703:7): [True: 16.9k, False: 18.4k]
  ------------------
  704|  16.9k|			continue; /* Not on card, do not define the object */
  705|       |
  706|  18.4k|		strncpy(obj_info.app_label, objects[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  18.4k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  707|  18.4k|		r = sc_format_oid(&obj_info.app_oid, objects[i].aoid);
  708|  18.4k|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|  18.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (708:7): [True: 0, False: 18.4k]
  ------------------
  709|  18.4k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  710|       |
  711|       |		/* We can not read all the objects, as some need the PIN! */
  712|  18.4k|		if (objects[i].auth_id)
  ------------------
  |  Branch (712:7): [True: 2.87k, False: 15.5k]
  ------------------
  713|  2.87k|			sc_pkcs15_format_id(objects[i].auth_id, &obj_obj.auth_id);
  714|       |
  715|  18.4k|		strncpy(obj_obj.label, objects[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  18.4k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  716|  18.4k|		obj_obj.flags = objects[i].obj_flags;
  717|       |
  718|  18.4k|		r = sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT,
  ------------------
  |  |  442|  18.4k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  719|  18.4k|			&obj_obj, &obj_info);
  720|       |
  721|  18.4k|		if (r < 0)
  ------------------
  |  Branch (721:7): [True: 0, False: 18.4k]
  ------------------
  722|  18.4k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  723|  18.4k|	}
  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|    957|	sc_log(card->ctx,  "PIV-II adding certs...");
  ------------------
  |  |   71|    957|#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|  24.8k|	for (i = 0; i < PIV_NUM_CERTS; i++) {
  ------------------
  |  |  345|  24.8k|#define PIV_NUM_CERTS 25
  ------------------
  |  Branch (737:14): [True: 23.9k, False: 957]
  ------------------
  738|  23.9k|		struct sc_pkcs15_cert_info cert_info;
  739|  23.9k|		struct sc_pkcs15_object    cert_obj;
  740|  23.9k|		sc_pkcs15_der_t   cert_der;
  741|  23.9k|		sc_pkcs15_cert_t *cert_out = NULL;
  742|  23.9k|		int private_obj;
  743|       |
  744|  23.9k|		ckis[i].cert_found = 0;
  745|  23.9k|		ckis[i].key_alg = -1;
  746|  23.9k|		ckis[i].pubkey_found = 0;
  747|  23.9k|		ckis[i].pubkey_from_file = 0;
  748|  23.9k|		ckis[i].pubkey_len = 0;
  749|  23.9k|		ckis[i].pubkey_from_cert = NULL;
  750|  23.9k|		ckis[i].cert_keyUsage = 0;
  751|  23.9k|		ckis[i].cert_keyUsage_present = 0;
  752|  23.9k|		ckis[i].pub_usage = 0;
  753|  23.9k|		ckis[i].priv_usage = 0;
  754|       |
  755|  23.9k|		memset(&cert_info, 0, sizeof(cert_info));
  756|  23.9k|		memset(&cert_obj,  0, sizeof(cert_obj));
  757|       |
  758|  23.9k|		sc_pkcs15_format_id(certs[i].id, &cert_info.id);
  759|  23.9k|		cert_info.authority = certs[i].authority;
  760|  23.9k|		sc_format_path(certs[i].path, &cert_info.path);
  761|       |
  762|  23.9k|		strncpy(cert_obj.label, certs[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  23.9k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  763|  23.9k|		cert_obj.flags = certs[i].obj_flags;
  764|       |
  765|       |		/* See if the cert might be present or not. */
  766|  23.9k|		r = sc_card_ctl(card, SC_CARDCTL_PIV_OBJECT_PRESENT, &cert_info.path);
  767|  23.9k|		if (r == 1) {
  ------------------
  |  Branch (767:7): [True: 15.7k, False: 8.18k]
  ------------------
  768|  15.7k|			sc_log(card->ctx,  "Cert can not be present,i=%d", i);
  ------------------
  |  |   71|  15.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__
  |  |  ------------------
  ------------------
  769|  15.7k|			continue;
  770|  15.7k|		}
  771|       |
  772|  8.18k|		private_obj = cert_obj.flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|  8.18k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  773|  8.18k|		r = sc_pkcs15_read_file(p15card, &cert_info.path, &cert_der.value, &cert_der.len, private_obj);
  774|       |
  775|  8.18k|		if (r) {
  ------------------
  |  Branch (775:7): [True: 6.17k, False: 2.01k]
  ------------------
  776|  6.17k|			sc_log(card->ctx,  "No cert found,i=%d", i);
  ------------------
  |  |   71|  6.17k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  777|  6.17k|			continue;
  778|  6.17k|		}
  779|       |
  780|  2.01k|		ckis[i].cert_found = 1;
  781|       |		/* cache it using the PKCS15 emulation objects */
  782|       |		/* as it does not change */
  783|  2.01k|		if (cert_der.value) {
  ------------------
  |  Branch (783:7): [True: 2.01k, False: 0]
  ------------------
  784|  2.01k|			cert_info.value.value = cert_der.value;
  785|  2.01k|			cert_info.value.len = cert_der.len;
  786|  2.01k|			if (!p15card->opts.use_file_cache
  ------------------
  |  Branch (786:8): [True: 2.01k, False: 0]
  ------------------
  787|  2.01k|			    || (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|  2.01k|				cert_info.path.len = 0; /* use in mem cert from now on */
  789|  2.01k|			}
  790|  2.01k|		}
  791|       |		/* following will find the cached cert in cert_info */
  792|  2.01k|		r =  sc_pkcs15_read_certificate(p15card, &cert_info, private_obj, &cert_out);
  793|  2.01k|		if (r < 0 || cert_out == NULL || cert_out->key == NULL) {
  ------------------
  |  Branch (793:7): [True: 718, False: 1.29k]
  |  Branch (793:16): [True: 0, False: 1.29k]
  |  Branch (793:36): [True: 11, False: 1.28k]
  ------------------
  794|    729|			sc_log(card->ctx,  "Failed to read/parse the certificate r=%d",r);
  ------------------
  |  |   71|    729|#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|    729|			if (cert_out != NULL)
  ------------------
  |  Branch (795:8): [True: 11, False: 718]
  ------------------
  796|     11|				sc_pkcs15_free_certificate(cert_out);
  797|    729|			free(cert_der.value);
  798|    729|			continue;
  799|    729|		}
  800|       |
  801|       |		/* set the token name to the name of the CN of the first certificate */
  802|  1.28k|		if (!token_name) {
  ------------------
  |  Branch (802:7): [True: 1.25k, False: 26]
  ------------------
  803|  1.25k|			u8 * cn_name = NULL;
  804|  1.25k|			size_t cn_len = 0;
  805|  1.25k|			static const struct sc_object_id cn_oid = {{ 2, 5, 4, 3, -1 }};
  806|  1.25k|			r = sc_pkcs15_get_name_from_dn(card->ctx, cert_out->subject,
  807|  1.25k|				cert_out->subject_len, &cn_oid, &cn_name, &cn_len);
  808|  1.25k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.25k|#define SC_SUCCESS				0
  ------------------
  |  Branch (808:8): [True: 12, False: 1.24k]
  ------------------
  809|     12|				token_name = malloc (cn_len+1);
  810|     12|				if (!token_name) {
  ------------------
  |  Branch (810:9): [True: 0, False: 12]
  ------------------
  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|     12|				memcpy(token_name, cn_name, cn_len);
  818|     12|				free(cn_name);
  819|     12|				token_name[cn_len] = 0;
  820|     12|				free(p15card->tokeninfo->label);
  821|     12|				p15card->tokeninfo->label = token_name;
  822|     12|			}
  823|  1.25k|		}
  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|  1.28k|		if (follows_nist_fascn == 0) {
  ------------------
  |  Branch (831:7): [True: 1.23k, False: 48]
  ------------------
  832|  1.23k|			struct sc_object_id keyUsage_oid={{2,5,29,15,-1}};
  833|  1.23k|			int r = 0;
  834|       |
  835|  1.23k|			r = sc_pkcs15_get_bitstring_extension(card->ctx, cert_out,
  836|  1.23k|				&keyUsage_oid,
  837|  1.23k|				&ckis[i].cert_keyUsage, NULL);
  838|  1.23k|			if ( r >= 0)
  ------------------
  |  Branch (838:9): [True: 0, False: 1.23k]
  ------------------
  839|      0|				ckis[i].cert_keyUsage_present = 1;
  840|       |				/* TODO if no key usage, we could set all uses */
  841|  1.23k|		}
  842|       |
  843|       |
  844|  1.28k|		ckis[i].key_alg = cert_out->key->algorithm;
  845|  1.28k|		switch (cert_out->key->algorithm) {
  846|    385|			case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|    385|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (846:4): [True: 385, False: 900]
  ------------------
  847|       |				/* save pubkey_len for pub and priv */
  848|    385|				ckis[i].pubkey_len = cert_out->key->u.rsa.modulus.len * 8;
  849|       |				/* See RFC 5280 and PKCS#11 V2.40 */
  850|    385|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (850:9): [True: 0, False: 385]
  ------------------
  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|    385|				break;
  901|       |
  902|    900|			case SC_ALGORITHM_EC:
  ------------------
  |  |   79|    900|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (902:4): [True: 900, False: 385]
  ------------------
  903|    900|			case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   81|    900|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (903:4): [True: 0, False: 1.28k]
  ------------------
  904|    900|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|    900|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (904:4): [True: 0, False: 1.28k]
  ------------------
  905|    900|				ckis[i].pubkey_len = cert_out->key->u.ec.params.field_length;
  906|    900|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (906:9): [True: 0, False: 900]
  ------------------
  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|    900|				break;
  945|       |
  946|      0|			default:
  ------------------
  |  Branch (946:4): [True: 0, False: 1.28k]
  ------------------
  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|  1.28k|		}
  950|  1.28k|		if (i < PIV_NUM_KEYS) { /* Only save pub key if card can have private key */
  ------------------
  |  |  346|  1.28k|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (950:7): [True: 1.27k, False: 12]
  ------------------
  951|  1.27k|			ckis[i].pubkey_from_cert = cert_out->key;
  952|  1.27k|			cert_out->key = NULL;
  953|  1.27k|		}
  954|  1.28k|		sc_pkcs15_free_certificate(cert_out);
  955|       |
  956|  1.28k|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  957|  1.28k|		if (r < 0) {
  ------------------
  |  Branch (957:7): [True: 0, False: 1.28k]
  ------------------
  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|  1.28k|	}
  962|       |
  963|       |	/* set pins */
  964|    957|	sc_log(card->ctx,  "PIV-II adding pins...");
  ------------------
  |  |   71|    957|#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.82k|	for (i = 0; pins[i].label; i++) {
  ------------------
  |  Branch (965:14): [True: 2.87k, False: 957]
  ------------------
  966|  2.87k|		struct sc_pkcs15_auth_info pin_info;
  967|  2.87k|		struct sc_pkcs15_object   pin_obj;
  968|  2.87k|		const char * label;
  969|  2.87k|		int pin_ref;
  970|       |
  971|       |		/* the SignPIN is only used with minidriver */
  972|  2.87k|		if (pins[i].cardmod && (strcmp(card->ctx->app_name, "cardmod") != 0))
  ------------------
  |  Branch (972:7): [True: 957, False: 1.91k]
  |  Branch (972:26): [True: 957, False: 0]
  ------------------
  973|    957|			continue;
  974|       |
  975|  1.91k|		memset(&pin_info, 0, sizeof(pin_info));
  976|  1.91k|		memset(&pin_obj,  0, sizeof(pin_obj));
  977|       |
  978|  1.91k|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|  1.91k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  979|  1.91k|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
  980|  1.91k|		pin_info.attrs.pin.reference     = pins[i].ref;
  981|  1.91k|		pin_info.attrs.pin.flags         = pins[i].flags;
  982|  1.91k|		pin_info.attrs.pin.type          = pins[i].type;
  983|  1.91k|		pin_info.attrs.pin.min_length    = pins[i].minlen;
  984|  1.91k|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
  985|  1.91k|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
  986|  1.91k|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
  987|  1.91k|		pin_info.tries_left              = pins[i].tries_left;
  988|  1.91k|		sc_format_path(pins[i].path, &pin_info.path);
  989|       |
  990|  1.91k|		label = pins[i].label;
  991|  1.91k|		if ((i == 0 || pins[i].cardmod) &&
  ------------------
  |  Branch (991:8): [True: 957, False: 957]
  |  Branch (991:18): [True: 0, False: 957]
  ------------------
  992|    957|			sc_card_ctl(card, SC_CARDCTL_PIV_PIN_PREFERENCE,
  ------------------
  |  Branch (992:4): [True: 957, False: 0]
  ------------------
  993|    957|					&pin_ref) == 0 &&
  994|    957|				pin_ref == 0x00) { /* must be 80 for PIV pin, or 00 for Global PIN */
  ------------------
  |  Branch (994:5): [True: 1, False: 956]
  ------------------
  995|      1|			pin_info.attrs.pin.reference = pin_ref;
  996|      1|			label = "Global PIN";
  997|      1|		}
  998|       |
  999|  1.91k|		strncpy(pin_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  1.91k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1000|  1.91k|		pin_obj.flags = pins[i].obj_flags;
 1001|  1.91k|		if ((i == 0 || pins[i].cardmod)) {
  ------------------
  |  Branch (1001:8): [True: 957, False: 957]
  |  Branch (1001:18): [True: 0, False: 957]
  ------------------
 1002|       |			/*
 1003|       |			 * according to description of "RESET RETRY COUNTER"
 1004|       |			 * command in specs PUK can only unblock PIV PIN
 1005|       |			 */
 1006|    957|			pin_obj.auth_id.len = 1;
 1007|    957|			pin_obj.auth_id.value[0] = 2;
 1008|    957|		}
 1009|       |
 1010|  1.91k|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
 1011|  1.91k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add PIN");
  ------------------
  |  |  184|  1.91k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.91k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.91k|	int _ret = (r); \
  |  |  |  |  178|  1.91k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 1.91k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.91k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.91k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1012|  1.91k|	}
 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|    957|	sc_log(card->ctx,  "PIV-II adding pub keys...");
  ------------------
  |  |   71|    957|#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|  23.7k|	for (i = 0; i < PIV_NUM_KEYS; i++) {
  ------------------
  |  |  346|  23.7k|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (1020:14): [True: 22.7k, False: 947]
  ------------------
 1021|  22.7k|		struct sc_pkcs15_pubkey_info pubkey_info;
 1022|  22.7k|		struct sc_pkcs15_object     pubkey_obj;
 1023|  22.7k|		struct sc_pkcs15_pubkey *p15_key = NULL;
 1024|       |
 1025|  22.7k|		memset(&pubkey_info, 0, sizeof(pubkey_info));
 1026|  22.7k|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
 1027|       |
 1028|       |
 1029|  22.7k|		sc_pkcs15_format_id(pubkeys[i].id, &pubkey_info.id);
 1030|  22.7k|		pubkey_info.native        = 1;
 1031|  22.7k|		pubkey_info.key_reference = pubkeys[i].ref;
 1032|       |
 1033|       |//		sc_format_path(pubkeys[i].path, &pubkey_info.path);
 1034|       |
 1035|  22.7k|		strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  22.7k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1036|       |
 1037|  22.7k|		pubkey_obj.flags = pubkeys[i].obj_flags;
 1038|       |
 1039|  22.7k|		if (pubkeys[i].auth_id)
  ------------------
  |  Branch (1039:7): [True: 0, False: 22.7k]
  ------------------
 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|  22.7k|		if (ckis[i].cert_found == 0 ) { /*  no cert found */
  ------------------
  |  Branch (1048:7): [True: 20.7k, False: 1.98k]
  ------------------
 1049|  20.7k|			char * filename = NULL;
 1050|       |
 1051|  20.7k|			sc_log(card->ctx, "No cert for this pub key i=%d",i);
  ------------------
  |  |   71|  20.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__
  |  |  ------------------
  ------------------
 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|  20.7k|			sc_log(card->ctx, "DEE look for env %s",
  ------------------
  |  |   71|  41.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 20.7k, False: 0]
  |  |  ------------------
  ------------------
 1063|  20.7k|					pubkeys[i].getenvname?pubkeys[i].getenvname:"NULL");
 1064|       |
 1065|  20.7k|			if (pubkeys[i].getenvname == NULL)
  ------------------
  |  Branch (1065:8): [True: 0, False: 20.7k]
  ------------------
 1066|      0|				continue;
 1067|       |
 1068|  20.7k|			filename = getenv(pubkeys[i].getenvname);
 1069|  20.7k|			sc_log(card->ctx, "DEE look for file %s", filename?filename:"NULL");
  ------------------
  |  |   71|  41.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 20.7k]
  |  |  ------------------
  ------------------
 1070|  20.7k|			if (filename == NULL)
  ------------------
  |  Branch (1070:8): [True: 20.7k, False: 0]
  ------------------
 1071|  20.7k|				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.98k|		else if (ckis[i].pubkey_from_cert)   {
  ------------------
  |  Branch (1118:12): [True: 1.27k, False: 712]
  ------------------
 1119|  1.27k|			r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, ckis[i].pubkey_from_cert,
 1120|  1.27k|				&pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
 1121|  1.27k|			LOG_TEST_GOTO_ERR(card->ctx, r, "SPKI encode public key error");
  ------------------
  |  |  184|  1.27k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.27k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.27k|	int _ret = (r); \
  |  |  |  |  178|  1.27k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 10, False: 1.26k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.26k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1122|       |
 1123|  1.26k|			pubkey_obj.emulated = ckis[i].pubkey_from_cert;
 1124|  1.26k|			ckis[i].pubkey_from_cert = NULL;
 1125|  1.26k|		}
 1126|       |
 1127|  1.97k|		sc_log(card->ctx, "adding pubkey for %d keyalg=%lu", i, ckis[i].key_alg);
  ------------------
  |  |   71|  1.97k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1128|  1.97k|		switch (ckis[i].key_alg) {
 1129|    371|			case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|    371|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1129:4): [True: 371, False: 1.60k]
  ------------------
 1130|    371|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1130:9): [True: 0, False: 371]
  ------------------
 1131|      0|					pubkey_info.usage =  ckis[i].pub_usage;
 1132|    371|				} else {
 1133|    371|					pubkey_info.usage = pubkeys[i].usage_rsa;
 1134|    371|				}
 1135|    371|				pubkey_info.modulus_length = ckis[i].pubkey_len;
 1136|    371|				strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    371|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1137|       |
 1138|       |				/* should not fail */
 1139|    371|				r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1140|    371|				LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add RSA pubkey");
  ------------------
  |  |  184|    371|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    371|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    371|	int _ret = (r); \
  |  |  |  |  178|    371|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 371]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    371|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 371]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1141|       |
 1142|    371|				ckis[i].pubkey_found = 1;
 1143|    371|				break;
 1144|    892|			case SC_ALGORITHM_EC:
  ------------------
  |  |   79|    892|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1144:4): [True: 892, False: 1.08k]
  ------------------
 1145|    892|			case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   81|    892|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1145:4): [True: 0, False: 1.97k]
  ------------------
 1146|    892|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|    892|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1146:4): [True: 0, False: 1.97k]
  ------------------
 1147|    892|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1147:9): [True: 0, False: 892]
  ------------------
 1148|      0|					pubkey_info.usage = ckis[i].pub_usage;
 1149|    892|				} else {
 1150|    892|					pubkey_info.usage = pubkeys[i].usage_ec;
 1151|    892|				}
 1152|       |
 1153|    892|				pubkey_info.field_length = ckis[i].pubkey_len;
 1154|    892|				strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    892|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1155|       |
 1156|       |				/* should not fail */
 1157|       |
 1158|    892|				if (ckis[i].key_alg == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   81|    892|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1158:9): [True: 0, False: 892]
  ------------------
 1159|      0|					r = sc_pkcs15emu_add_eddsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1160|    892|				else if (ckis[i].key_alg == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|    892|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1160:14): [True: 0, False: 892]
  ------------------
 1161|      0|					r = sc_pkcs15emu_add_xeddsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1162|    892|				else
 1163|    892|					r = sc_pkcs15emu_add_ec_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1164|       |
 1165|    892|				LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add EC pubkey");
  ------------------
  |  |  184|    892|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    892|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    892|	int _ret = (r); \
  |  |  |  |  178|    892|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 892]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    892|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 892]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1166|       |
 1167|    892|				ckis[i].pubkey_found = 1;
 1168|    892|				break;
 1169|    712|			default:
  ------------------
  |  Branch (1169:4): [True: 712, False: 1.26k]
  ------------------
 1170|    712|				sc_log(card->ctx, "key_alg %lu not supported", ckis[i].key_alg);
  ------------------
  |  |   71|    712|#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|    712|				continue;
 1172|  1.97k|		}
 1173|  1.26k|		sc_log(card->ctx, "USAGE: cert_keyUsage_present:%d usage:0x%8.8x",
  ------------------
  |  |   71|  1.26k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1174|  1.26k|				ckis[i].cert_keyUsage_present, pubkey_info.usage);
 1175|  1.26k|	}
 1176|       |
 1177|       |
 1178|       |	/* set private keys */
 1179|    947|	sc_log(card->ctx,  "PIV-II adding private keys...");
  ------------------
  |  |   71|    947|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1180|  23.6k|	for (i = 0; i < PIV_NUM_KEYS; i++) {
  ------------------
  |  |  346|  23.6k|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (1180:14): [True: 22.7k, False: 947]
  ------------------
 1181|  22.7k|		struct sc_pkcs15_prkey_info prkey_info;
 1182|  22.7k|		struct sc_pkcs15_object     prkey_obj;
 1183|       |
 1184|  22.7k|		memset(&prkey_info, 0, sizeof(prkey_info));
 1185|  22.7k|		memset(&prkey_obj,  0, sizeof(prkey_obj));
 1186|       |
 1187|  22.7k|		if (ckis[i].cert_found == 0 && ckis[i].pubkey_found == 0)
  ------------------
  |  Branch (1187:7): [True: 20.7k, False: 1.96k]
  |  Branch (1187:34): [True: 20.7k, False: 0]
  ------------------
 1188|  20.7k|			continue; /* i.e. no cert or pubkey */
 1189|       |
 1190|  1.96k|		sc_pkcs15_format_id(prkeys[i].id, &prkey_info.id);
 1191|  1.96k|		prkey_info.native        = 1;
 1192|  1.96k|		prkey_info.key_reference = prkeys[i].ref;
 1193|  1.96k|		sc_format_path(prkeys[i].path, &prkey_info.path);
 1194|       |
 1195|  1.96k|		strncpy(prkey_obj.label, prkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  1.96k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1196|  1.96k|		prkey_obj.flags = prkeys[i].obj_flags;
 1197|  1.96k|		prkey_obj.user_consent = prkeys[i].user_consent; /* only Sign key */
 1198|       |
 1199|  1.96k|		if (prkeys[i].auth_id)
  ------------------
  |  Branch (1199:7): [True: 1.75k, False: 217]
  ------------------
 1200|  1.75k|			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.96k|		if (prkey_obj.user_consent && (strcmp(card->ctx->app_name, "cardmod") == 0))
  ------------------
  |  Branch (1203:7): [True: 255, False: 1.71k]
  |  Branch (1203:33): [True: 0, False: 255]
  ------------------
 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.96k|		if (ckis[i].pubkey_from_file == 1) {
  ------------------
  |  Branch (1215:7): [True: 0, False: 1.96k]
  ------------------
 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.96k|		switch (ckis[i].key_alg) {
 1221|    371|			case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|    371|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1221:4): [True: 371, False: 1.59k]
  ------------------
 1222|    371|				if(ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1222:8): [True: 0, False: 371]
  ------------------
 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|    371|				} else {
 1229|    371|					prkey_info.usage |= prkeys[i].usage_rsa;
 1230|    371|				}
 1231|    371|				prkey_info.modulus_length= ckis[i].pubkey_len;
 1232|    371|				r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
 1233|    371|				break;
 1234|    889|			case SC_ALGORITHM_EC:
  ------------------
  |  |   79|    889|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1234:4): [True: 889, False: 1.07k]
  ------------------
 1235|    889|			case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   81|    889|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1235:4): [True: 0, False: 1.96k]
  ------------------
 1236|    889|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|    889|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1236:4): [True: 0, False: 1.96k]
  ------------------
 1237|    889|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1237:9): [True: 0, False: 889]
  ------------------
 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|    889|				} else {
 1244|    889|					prkey_info.usage  |= prkeys[i].usage_ec;
 1245|    889|				}
 1246|    889|				prkey_info.field_length = ckis[i].pubkey_len;
 1247|    889|				sc_log(card->ctx, "DEE added key_alg %2.2lx prkey_obj.flags %8.8x",
  ------------------
  |  |   71|    889|#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|    889|					 ckis[i].key_alg, prkey_obj.flags);
 1249|       |
 1250|    889|				if (ckis[i].key_alg == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   81|    889|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1250:9): [True: 0, False: 889]
  ------------------
 1251|      0|					r = sc_pkcs15emu_add_eddsa_prkey(p15card, &prkey_obj, &prkey_info);
 1252|    889|				else if (ckis[i].key_alg == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|    889|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1252:14): [True: 0, False: 889]
  ------------------
 1253|      0|					r = sc_pkcs15emu_add_xeddsa_prkey(p15card, &prkey_obj, &prkey_info);
 1254|    889|				else
 1255|    889|					r = sc_pkcs15emu_add_ec_prkey(p15card, &prkey_obj, &prkey_info);
 1256|    889|				break;
 1257|    707|			default:
  ------------------
  |  Branch (1257:4): [True: 707, False: 1.26k]
  ------------------
 1258|    707|				sc_log(card->ctx, "Unsupported key_alg %lu", ckis[i].key_alg);
  ------------------
  |  |   71|    707|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1259|    707|				r = 0; /* we just skip this one */
 1260|  1.96k|		}
 1261|  1.96k|		sc_log(card->ctx, "USAGE: cert_keyUsage_present:%d usage:0x%8.8x", ckis[i].cert_keyUsage_present, prkey_info.usage);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1262|  1.96k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add Private key");
  ------------------
  |  |  184|  1.96k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.96k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.96k|	int _ret = (r); \
  |  |  |  |  178|  1.96k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 1.96k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.96k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.96k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1263|  1.96k|	}
 1264|       |
 1265|    947|	p15card->ops.get_guid = piv_get_guid;
 1266|       |
 1267|    947|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    947|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    947|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    947|	int _ret = r; \
  |  |  |  |  155|    947|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 947, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    947|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 947]
  |  |  |  |  ------------------
  |  |  |  |  157|    947|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    947|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    947|	return _ret; \
  |  |  |  |  163|    947|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|     32|{
  158|     32|	sc_context_t *ctx = p15card->card->ctx;
  159|     32|	struct sc_pkcs15_prkey_info info;
  160|     32|	int r, i, gostr3410_params[3];
  161|     32|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  162|     32|	size_t usage_len = sizeof(info.usage);
  163|     32|	size_t af_len = sizeof(info.access_flags);
  164|     32|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  165|     32|	struct sc_asn1_entry asn1_com_prkey_attr[C_ASN1_COM_PRKEY_ATTR_SIZE];
  166|     32|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  167|     32|	struct sc_asn1_entry asn1_prk_rsa_attr[C_ASN1_PRK_RSA_ATTR_SIZE];
  168|     32|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOSTR3410KEY_ATTR_SIZE];
  169|     32|	struct sc_asn1_entry asn1_prk_gostr3410_attr[C_ASN1_PRK_GOSTR3410_ATTR_SIZE];
  170|     32|	struct sc_asn1_entry asn1_ecckey_attr[C_ASN1_ECCKEY_ATTR];
  171|     32|	struct sc_asn1_entry asn1_prk_ecc_attr[C_ASN1_PRK_ECC_ATTR];
  172|     32|	struct sc_asn1_entry asn1_prkey[C_ASN1_PRKEY_SIZE];
  173|     32|	struct sc_asn1_entry asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE];
  174|     32|	struct sc_asn1_pkcs15_object rsa_prkey_obj = {obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_rsa_attr};
  175|     32|	struct sc_asn1_pkcs15_object gostr3410_prkey_obj = {obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_gostr3410_attr};
  176|     32|	struct sc_asn1_pkcs15_object ecc_prkey_obj = { obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_ecc_attr };
  177|     32|	u8 ec_domain[32];
  178|     32|	size_t ec_domain_len = sizeof(ec_domain);
  179|       |
  180|     32|	sc_copy_asn1_entry(c_asn1_prkey, asn1_prkey);
  181|     32|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  182|       |
  183|     32|	sc_copy_asn1_entry(c_asn1_prk_rsa_attr, asn1_prk_rsa_attr);
  184|     32|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  185|     32|	sc_copy_asn1_entry(c_asn1_prk_gostr3410_attr, asn1_prk_gostr3410_attr);
  186|     32|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  187|     32|	sc_copy_asn1_entry(c_asn1_prk_ecc_attr, asn1_prk_ecc_attr);
  188|     32|	sc_copy_asn1_entry(c_asn1_ecckey_attr, asn1_ecckey_attr);
  189|       |
  190|     32|	sc_copy_asn1_entry(c_asn1_com_prkey_attr, asn1_com_prkey_attr);
  191|     32|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  192|       |
  193|     32|	sc_format_asn1_entry(asn1_prkey + 0, &rsa_prkey_obj, NULL, 0);
  194|     32|	sc_format_asn1_entry(asn1_prkey + 1, &ecc_prkey_obj, NULL, 0);
  195|     32|	sc_format_asn1_entry(asn1_prkey + 2, &gostr3410_prkey_obj, NULL, 0);
  196|       |
  197|     32|	sc_format_asn1_entry(asn1_prk_rsa_attr + 0, asn1_rsakey_attr, NULL, 0);
  198|     32|	sc_format_asn1_entry(asn1_prk_gostr3410_attr + 0, asn1_gostr3410key_attr, NULL, 0);
  199|     32|	sc_format_asn1_entry(asn1_prk_ecc_attr + 0, asn1_ecckey_attr, NULL, 0);
  200|       |
  201|     32|	sc_format_asn1_entry(asn1_rsakey_attr + 0, &info.path, NULL, 0);
  202|     32|	sc_format_asn1_entry(asn1_rsakey_attr + 1, &info.modulus_length, NULL, 0);
  203|       |
  204|     32|	sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &info.path, NULL, 0);
  205|     32|	sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &gostr3410_params[0], NULL, 0);
  206|     32|	sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &gostr3410_params[1], NULL, 0);
  207|     32|	sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &gostr3410_params[2], NULL, 0);
  208|       |
  209|     32|	sc_format_asn1_entry(asn1_ecckey_attr + 0, &info.path, NULL, 0);
  210|     32|	sc_format_asn1_entry(asn1_ecckey_attr + 1, &info.field_length, NULL, 0);
  211|     32|	sc_format_asn1_entry(asn1_ecckey_attr + 3, ec_domain, &ec_domain_len, 0);
  212|       |
  213|     32|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info.id, NULL, 0);
  214|     32|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info.usage, &usage_len, 0);
  215|     32|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info.native, NULL, 0);
  216|     32|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info.access_flags, &af_len, 0);
  217|     32|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info.key_reference, NULL, 0);
  218|       |
  219|    544|	for (i=0; i<SC_MAX_SUPPORTED_ALGORITHMS && (asn1_supported_algorithms + i)->name; i++)
  ------------------
  |  |   61|  1.08k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (219:12): [True: 512, False: 32]
  |  Branch (219:45): [True: 512, False: 0]
  ------------------
  220|    512|		sc_format_asn1_entry(asn1_supported_algorithms + i, &info.algo_refs[i], NULL, 0);
  221|     32|	sc_format_asn1_entry(asn1_com_key_attr + 5, asn1_supported_algorithms, NULL, 0);
  222|       |
  223|     32|	sc_format_asn1_entry(asn1_com_prkey_attr + 0, &info.subject.value, &info.subject.len, 0);
  224|       |
  225|       |	/* Fill in defaults */
  226|     32|	memset(&info, 0, sizeof(info));
  227|     32|	info.key_reference = -1;
  228|     32|	info.native = 1;
  229|     32|	memset(gostr3410_params, 0, sizeof(gostr3410_params));
  230|       |
  231|     32|	r = sc_asn1_decode_choice(ctx, asn1_prkey, *buf, *buflen, buf, buflen);
  232|     32|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     32|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (232:6): [True: 11, False: 21]
  ------------------
  233|     11|		goto err;
  234|     21|	LOG_TEST_GOTO_ERR(ctx, r, "PrKey DF ASN.1 decoding failed");
  ------------------
  |  |  184|     21|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     21|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     21|	int _ret = (r); \
  |  |  |  |  178|     21|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 20, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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|     21|} 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|     32|err:
  360|     32|	if (r < 0) {
  ------------------
  |  Branch (360:6): [True: 32, False: 0]
  ------------------
  361|       |		/* This might have allocated something. If so, clear it now */
  362|     32|		free(info.subject.value);
  363|     32|		sc_pkcs15_free_key_params(&info.params);
  364|     32|	}
  365|       |
  366|     32|	return r;
  367|      0|}
sc_pkcs15_free_prkey_info:
  594|  4.83k|{
  595|  4.83k|	if (!key)
  ------------------
  |  Branch (595:6): [True: 0, False: 4.83k]
  ------------------
  596|      0|		return;
  597|       |
  598|  4.83k|	if (key->subject.value)
  ------------------
  |  Branch (598:6): [True: 225, False: 4.61k]
  ------------------
  599|    225|		free(key->subject.value);
  600|       |
  601|  4.83k|	sc_pkcs15_free_key_params(&key->params);
  602|       |
  603|  4.83k|	sc_aux_data_free(&key->aux_data);
  604|       |
  605|  4.83k|	free(key);
  606|  4.83k|}

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

sc_pkcs15_decode_pukdf_entry:
  202|    226|{
  203|    226|	struct sc_context *ctx = p15card->card->ctx;
  204|    226|	struct sc_pkcs15_pubkey_info *info;
  205|    226|	int r, gostr3410_params[3];
  206|    226|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  207|    226|	size_t usage_len, af_len;
  208|    226|	struct sc_pkcs15_der *der = &obj->content;
  209|    226|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  210|    226|	struct sc_asn1_entry asn1_com_pubkey_attr[C_ASN1_COM_PUBKEY_ATTR_SIZE];
  211|    226|	struct sc_asn1_entry asn1_rsakey_value_choice[C_ASN1_RSAKEY_VALUE_CHOICE_SIZE];
  212|    226|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  213|    226|	struct sc_asn1_entry asn1_rsa_type_attr[C_ASN1_RSA_TYPE_ATTR_SIZE];
  214|    226|	struct sc_asn1_entry asn1_eckey_value_choice[C_ASN1_ECKEY_VALUE_CHOICE_SIZE];
  215|    226|	struct sc_asn1_entry asn1_eckey_attr[C_ASN1_ECKEY_ATTR_SIZE];
  216|    226|	struct sc_asn1_entry asn1_ec_type_attr[C_ASN1_EC_TYPE_ATTR_SIZE];
  217|    226|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOST3410KEY_ATTR_SIZE];
  218|    226|	struct sc_asn1_entry asn1_gostr3410_type_attr[C_ASN1_GOST3410_TYPE_ATTR_SIZE];
  219|    226|	struct sc_asn1_entry asn1_pubkey_choice[C_ASN1_PUBKEY_CHOICE_SIZE];
  220|    226|	struct sc_asn1_entry asn1_pubkey[C_ASN1_PUBKEY_SIZE];
  221|    226|	struct sc_asn1_pkcs15_object rsakey_obj = { obj, asn1_com_key_attr,
  222|    226|			asn1_com_pubkey_attr, asn1_rsa_type_attr };
  223|    226|	struct sc_asn1_pkcs15_object eckey_obj = { obj, asn1_com_key_attr,
  224|    226|			asn1_com_pubkey_attr, asn1_ec_type_attr };
  225|    226|	struct sc_asn1_pkcs15_object gostr3410key_obj =  { obj, asn1_com_key_attr,
  226|    226|			asn1_com_pubkey_attr, asn1_gostr3410_type_attr };
  227|       |
  228|    226|	info = calloc(1, sizeof *info);
  229|    226|	if (info == NULL) {
  ------------------
  |  Branch (229:6): [True: 0, False: 226]
  ------------------
  230|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  231|      0|		goto err;
  232|      0|	}
  233|    226|	usage_len = sizeof(info->usage);
  234|    226|	af_len = sizeof(info->access_flags);
  235|       |
  236|    226|	sc_copy_asn1_entry(c_asn1_pubkey, asn1_pubkey);
  237|    226|	sc_copy_asn1_entry(c_asn1_pubkey_choice, asn1_pubkey_choice);
  238|    226|	sc_copy_asn1_entry(c_asn1_rsa_type_attr, asn1_rsa_type_attr);
  239|    226|	sc_copy_asn1_entry(c_asn1_rsakey_value_choice, asn1_rsakey_value_choice);
  240|    226|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  241|    226|	sc_copy_asn1_entry(c_asn1_ec_type_attr, asn1_ec_type_attr);
  242|    226|	sc_copy_asn1_entry(c_asn1_eckey_value_choice, asn1_eckey_value_choice);
  243|    226|	sc_copy_asn1_entry(c_asn1_eckey_attr, asn1_eckey_attr);
  244|    226|	sc_copy_asn1_entry(c_asn1_gostr3410_type_attr, asn1_gostr3410_type_attr);
  245|    226|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  246|    226|	sc_copy_asn1_entry(c_asn1_com_pubkey_attr, asn1_com_pubkey_attr);
  247|    226|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  248|       |
  249|    226|	sc_format_asn1_entry(asn1_com_pubkey_attr + 0, &info->subject.value, &info->subject.len, 0);
  250|       |
  251|    226|	sc_format_asn1_entry(asn1_pubkey_choice + 0, &rsakey_obj, NULL, 0);
  252|    226|	sc_format_asn1_entry(asn1_pubkey_choice + 1, &gostr3410key_obj, NULL, 0);
  253|    226|	sc_format_asn1_entry(asn1_pubkey_choice + 2, &eckey_obj, NULL, 0);
  254|       |
  255|    226|	sc_format_asn1_entry(asn1_rsa_type_attr + 0, asn1_rsakey_attr, NULL, 0);
  256|       |
  257|    226|	sc_format_asn1_entry(asn1_rsakey_value_choice + 0, &info->path, NULL, 0);
  258|    226|	sc_format_asn1_entry(asn1_rsakey_value_choice + 1, &der->value, &der->len, 0);
  259|       |
  260|    226|	sc_format_asn1_entry(asn1_rsakey_attr + 0, asn1_rsakey_value_choice, NULL, 0);
  261|    226|	sc_format_asn1_entry(asn1_rsakey_attr + 1, &info->modulus_length, NULL, 0);
  262|       |
  263|    226|	sc_format_asn1_entry(asn1_ec_type_attr + 0, asn1_eckey_attr, NULL, 0);
  264|       |
  265|    226|	sc_format_asn1_entry(asn1_eckey_value_choice + 0, &info->path, NULL, 0);
  266|    226|	sc_format_asn1_entry(asn1_eckey_value_choice + 1, &der->value, &der->len, 0);
  267|       |
  268|    226|	sc_format_asn1_entry(asn1_eckey_attr + 0, asn1_eckey_value_choice, NULL, 0);
  269|       |
  270|    226|	sc_format_asn1_entry(asn1_gostr3410_type_attr + 0, asn1_gostr3410key_attr, NULL, 0);
  271|       |
  272|    226|	sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &info->path, NULL, 0);
  273|    226|	sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &gostr3410_params[0], NULL, 0);
  274|    226|	sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &gostr3410_params[1], NULL, 0);
  275|    226|	sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &gostr3410_params[2], NULL, 0);
  276|       |
  277|    226|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info->id, NULL, 0);
  278|    226|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info->usage, &usage_len, 0);
  279|    226|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info->native, NULL, 0);
  280|    226|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info->access_flags, &af_len, 0);
  281|    226|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info->key_reference, NULL, 0);
  282|       |
  283|    226|	sc_format_asn1_entry(asn1_pubkey + 0, asn1_pubkey_choice, NULL, 0);
  284|       |
  285|       |	/* Fill in defaults */
  286|    226|	info->key_reference = -1;
  287|    226|	info->native = 1;
  288|    226|	memset(gostr3410_params, 0, sizeof(gostr3410_params));
  289|       |
  290|    226|	r = sc_asn1_decode(ctx, asn1_pubkey, *buf, *buflen, buf, buflen);
  291|    226|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    226|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (291:6): [True: 54, False: 172]
  ------------------
  292|     54|		goto err;
  293|    172|	LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  184|    172|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    172|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    172|	int _ret = (r); \
  |  |  |  |  178|    172|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 172, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    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
  |  |  |  |  ------------------
  |  |  |  |  180|    172|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    172|		goto err; \
  |  |  |  |  182|    172|	} \
  |  |  |  |  183|    172|} 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|    226|err:
  355|    226|	if (r < 0) {
  ------------------
  |  Branch (355:6): [True: 226, False: 0]
  ------------------
  356|    226|		sc_pkcs15_free_pubkey_info(info);
  357|    226|		if (der->len) {
  ------------------
  |  Branch (357:7): [True: 0, False: 226]
  ------------------
  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|    226|	}
  364|       |
  365|    226|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    226|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    226|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    226|	int _ret = r; \
  |  |  |  |  155|    226|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 226, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    226|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    226|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 226, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    226|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    226|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    226|	return _ret; \
  |  |  |  |  163|    226|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  366|    226|}
sc_pkcs15_decode_pubkey_rsa:
  563|  1.19k|{
  564|  1.19k|	struct sc_asn1_entry asn1_public_key[C_ASN1_PUBLIC_KEY_SIZE];
  565|  1.19k|	struct sc_asn1_entry asn1_rsa_pub_coefficients[C_ASN1_RSA_PUB_COEFFICIENTS_SIZE];
  566|  1.19k|	int r;
  567|       |
  568|  1.19k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.19k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.19k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.19k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.19k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.19k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|  1.19k|	sc_copy_asn1_entry(c_asn1_public_key, asn1_public_key);
  570|  1.19k|	sc_format_asn1_entry(asn1_public_key + 0, asn1_rsa_pub_coefficients, NULL, 0);
  571|       |
  572|  1.19k|	sc_copy_asn1_entry(c_asn1_rsa_pub_coefficients, asn1_rsa_pub_coefficients);
  573|  1.19k|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 0, &key->modulus.data, &key->modulus.len, 0);
  574|  1.19k|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 1, &key->exponent.data, &key->exponent.len, 0);
  575|       |
  576|  1.19k|	r = sc_asn1_decode(ctx, asn1_public_key, buf, buflen, NULL, NULL);
  577|  1.19k|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of public key failed");
  ------------------
  |  |  174|  1.19k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.19k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.19k|	int _ret = (r); \
  |  |  |  |  168|  1.19k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 107, False: 1.08k]
  |  |  |  |  ------------------
  |  |  |  |  169|    107|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    107|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    107|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    107|		return _ret; \
  |  |  |  |  172|    107|	} \
  |  |  |  |  173|  1.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  578|       |
  579|  1.08k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.08k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.08k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.08k|	int _ret = r; \
  |  |  |  |  155|  1.08k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.08k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.08k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.08k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.08k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.08k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.08k|	return _ret; \
  |  |  |  |  163|  1.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|  1.08k|}
sc_pkcs15_encode_pubkey_rsa:
  586|    816|{
  587|    816|	struct sc_asn1_entry asn1_public_key[C_ASN1_PUBLIC_KEY_SIZE];
  588|    816|	struct sc_asn1_entry asn1_rsa_pub_coefficients[C_ASN1_RSA_PUB_COEFFICIENTS_SIZE];
  589|    816|	int r;
  590|       |
  591|    816|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    816|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    816|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    816|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    816|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 816]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  592|    816|	sc_copy_asn1_entry(c_asn1_public_key, asn1_public_key);
  593|    816|	sc_format_asn1_entry(asn1_public_key + 0, asn1_rsa_pub_coefficients, NULL, 1);
  594|       |
  595|    816|	sc_copy_asn1_entry(c_asn1_rsa_pub_coefficients, asn1_rsa_pub_coefficients);
  596|    816|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 0, key->modulus.data, &key->modulus.len, 1);
  597|    816|	sc_format_asn1_entry(asn1_rsa_pub_coefficients + 1, key->exponent.data, &key->exponent.len, 1);
  598|       |
  599|    816|	r = sc_asn1_encode(ctx, asn1_public_key, buf, buflen);
  600|    816|	LOG_TEST_RET(ctx, r, "ASN.1 encoding failed");
  ------------------
  |  |  174|    816|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    816|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    816|	int _ret = (r); \
  |  |  |  |  168|    816|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 801]
  |  |  |  |  ------------------
  |  |  |  |  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|    816|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 801]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  601|       |
  602|    801|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    801|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    801|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    801|	int _ret = r; \
  |  |  |  |  155|    801|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 801, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    801|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 801]
  |  |  |  |  ------------------
  |  |  |  |  157|    801|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    801|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    801|	return _ret; \
  |  |  |  |  163|    801|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  603|    801|}
sc_pkcs15_encode_pubkey:
  769|    750|{
  770|    750|	if (key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   78|    750|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (770:6): [True: 750, False: 0]
  ------------------
  771|    750|		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.64k|{
  802|  1.64k|	int r = 0;
  803|  1.64k|	struct sc_asn1_entry  asn1_spki_key[2], asn1_spki_key_items[3];
  804|  1.64k|	struct sc_pkcs15_u8 pkey;
  805|  1.64k|	size_t key_len;
  806|       |
  807|  1.64k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.64k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.64k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.64k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.64k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.64k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  808|  1.64k|	pkey.value =  NULL;
  809|  1.64k|	pkey.len = 0;
  810|       |
  811|  1.64k|	sc_log(ctx, "Encoding public key with algorithm %lu", pubkey->algorithm);
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
  812|  1.64k|	if (!pubkey->alg_id)   {
  ------------------
  |  Branch (812:6): [True: 1, False: 1.64k]
  ------------------
  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.64k|	switch (pubkey->algorithm) {
  822|    893|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|    893|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (822:2): [True: 893, False: 750]
  ------------------
  823|    893|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   81|    893|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (823:2): [True: 0, False: 1.64k]
  ------------------
  824|    893|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|    893|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (824:2): [True: 0, False: 1.64k]
  ------------------
  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|    893|		key_len = pubkey->u.ec.ecpointQ.len * 8;
  831|    893|		pkey.value = pubkey->u.ec.ecpointQ.value;
  832|    893|		pkey.len = 0; /* flag as do not delete */
  833|       |
  834|    893|		if (pubkey->u.ec.params.named_curve || pubkey->u.ec.params.der.value)   {
  ------------------
  |  Branch (834:7): [True: 880, False: 13]
  |  Branch (834:42): [True: 0, False: 13]
  ------------------
  835|    880|			struct sc_ec_parameters *ec_params = NULL;
  836|       |
  837|    880|			r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
  838|    880|			LOG_TEST_RET(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  174|    880|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    880|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    880|	int _ret = (r); \
  |  |  |  |  168|    880|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 880]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    880|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 880]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  839|       |
  840|       |			/* EDDSA and XEDDSA only have algo and no param in SPKI */
  841|    880|			if (pubkey->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   79|    880|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (841:8): [True: 880, False: 0]
  ------------------
  842|    880|				ec_params = calloc(1, sizeof(struct sc_ec_parameters));
  843|    880|				if (!ec_params)
  ------------------
  |  Branch (843:9): [True: 0, False: 880]
  ------------------
  844|    880|					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|    880|				ec_params->type = 1;
  846|    880|				ec_params->der.value = calloc(1, pubkey->u.ec.params.der.len);
  847|    880|				if (!ec_params->der.value) {
  ------------------
  |  Branch (847:9): [True: 0, False: 880]
  ------------------
  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|    880|				memcpy(ec_params->der.value, pubkey->u.ec.params.der.value, pubkey->u.ec.params.der.len);
  852|    880|				ec_params->der.len = pubkey->u.ec.params.der.len;
  853|    880|			}
  854|       |			/* This could have been already allocated: avoid memory leak */
  855|    880|			sc_asn1_clear_algorithm_id(pubkey->alg_id);
  856|    880|			pubkey->alg_id->params = ec_params; /* NULL for EDDSA and XEDDSA */
  857|    880|		}
  858|    893|		break;
  859|    893|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   80|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (859:2): [True: 0, False: 1.64k]
  ------------------
  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|    750|	default:
  ------------------
  |  Branch (865:2): [True: 750, False: 893]
  ------------------
  866|    750|		r = sc_pkcs15_encode_pubkey(ctx, pubkey, &pkey.value, &pkey.len);
  867|    750|		key_len = pkey.len * 8;
  868|    750|		break;
  869|  1.64k|	}
  870|       |
  871|  1.64k|	if (r == 0) {
  ------------------
  |  Branch (871:6): [True: 1.63k, False: 11]
  ------------------
  872|  1.63k|		sc_copy_asn1_entry(c_asn1_spki_key, asn1_spki_key);
  873|  1.63k|		sc_copy_asn1_entry(c_asn1_spki_key_items, asn1_spki_key_items);
  874|  1.63k|		sc_format_asn1_entry(asn1_spki_key + 0, asn1_spki_key_items, NULL, 1);
  875|  1.63k|		sc_format_asn1_entry(asn1_spki_key_items + 0, pubkey->alg_id, NULL, 1);
  876|  1.63k|		sc_format_asn1_entry(asn1_spki_key_items + 1, pkey.value, &key_len, 1);
  877|       |
  878|  1.63k|		r =  sc_asn1_encode(ctx, asn1_spki_key, buf, len);
  879|  1.63k|	}
  880|       |
  881|       |	/*  pkey.len == 0 is flag to not delete */
  882|  1.64k|	if (pkey.len && pkey.value)
  ------------------
  |  Branch (882:6): [True: 739, False: 904]
  |  Branch (882:18): [True: 739, False: 0]
  ------------------
  883|    739|		free(pkey.value);
  884|       |
  885|  1.64k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  1.64k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.64k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.64k|	int _ret = r; \
  |  |  |  |  155|  1.64k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.64k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.64k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 1.63k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.64k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.64k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.64k|	return _ret; \
  |  |  |  |  163|  1.64k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  886|  1.64k|}
sc_pkcs15_decode_pubkey:
  892|  1.28k|{
  893|  1.28k|	if (key->algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   78|  1.28k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (893:6): [True: 1.19k, False: 91]
  ------------------
  894|  1.19k|		return sc_pkcs15_decode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
  895|     91|	if (key->algorithm == SC_ALGORITHM_GOSTR3410)
  ------------------
  |  |   80|     91|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (895:6): [True: 0, False: 91]
  ------------------
  896|      0|		return sc_pkcs15_decode_pubkey_gostr3410(ctx, &key->u.gostr3410, buf, len);
  897|     91|	if (key->algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   79|     91|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (897:6): [True: 0, False: 91]
  ------------------
  898|      0|		return sc_pkcs15_decode_pubkey_ec(ctx, &key->u.ec, buf, len);
  899|     91|	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   81|    182|#define SC_ALGORITHM_EDDSA		4
  ------------------
              	if (key->algorithm == SC_ALGORITHM_EDDSA || key->algorithm == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|     91|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (899:6): [True: 0, False: 91]
  |  Branch (899:46): [True: 0, False: 91]
  ------------------
  900|      0|		return sc_pkcs15_decode_pubkey_eddsa(ctx, &key->u.ec, buf, len);
  901|       |
  902|     91|	sc_log(ctx, "Decoding of public key type %lu not supported", key->algorithm);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  903|     91|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     91|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  904|     91|}
sc_pkcs15_erase_pubkey:
 1187|  3.90k|{
 1188|  3.90k|	if (key == NULL) {
  ------------------
  |  Branch (1188:6): [True: 0, False: 3.90k]
  ------------------
 1189|      0|		return;
 1190|      0|	}
 1191|  3.90k|	if (key->alg_id) {
  ------------------
  |  Branch (1191:6): [True: 2.31k, False: 1.59k]
  ------------------
 1192|  2.31k|		sc_asn1_clear_algorithm_id(key->alg_id);
 1193|  2.31k|		free(key->alg_id);
 1194|  2.31k|	}
 1195|  3.90k|	switch (key->algorithm) {
  ------------------
  |  Branch (1195:10): [True: 3.80k, False: 103]
  ------------------
 1196|  2.77k|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|  2.77k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1196:2): [True: 2.77k, False: 1.12k]
  ------------------
 1197|  2.77k|		free(key->u.rsa.modulus.data);
 1198|  2.77k|		free(key->u.rsa.exponent.data);
 1199|  2.77k|		break;
 1200|      0|	case SC_ALGORITHM_GOSTR3410:
  ------------------
  |  |   80|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (1200:2): [True: 0, False: 3.90k]
  ------------------
 1201|      0|		free(key->u.gostr3410.xy.data);
 1202|      0|		break;
 1203|  1.02k|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|  1.02k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1203:2): [True: 1.02k, False: 2.88k]
  ------------------
 1204|  1.02k|	case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   81|  1.02k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1204:2): [True: 0, False: 3.90k]
  ------------------
 1205|  1.02k|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|  1.02k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1205:2): [True: 0, False: 3.90k]
  ------------------
 1206|  1.02k|		free(key->u.ec.params.der.value);
 1207|  1.02k|		free(key->u.ec.params.named_curve);
 1208|  1.02k|		free(key->u.ec.ecpointQ.value);
 1209|  1.02k|		break;
 1210|  3.90k|	}
 1211|  3.90k|	sc_mem_clear(key, sizeof(*key));
 1212|  3.90k|}
sc_pkcs15_free_pubkey:
 1217|  9.26k|{
 1218|  9.26k|	if (!key)
  ------------------
  |  Branch (1218:6): [True: 5.35k, False: 3.90k]
  ------------------
 1219|  5.35k|		return;
 1220|  3.90k|	sc_pkcs15_erase_pubkey(key);
 1221|  3.90k|	free(key);
 1222|  3.90k|}
sc_pkcs15_free_pubkey_info:
 1227|  2.20k|{
 1228|  2.20k|	if (info) {
  ------------------
  |  Branch (1228:6): [True: 2.20k, False: 0]
  ------------------
 1229|  2.20k|		free(info->subject.value);
 1230|  2.20k|		free(info->direct.spki.value);
 1231|  2.20k|		free(info->direct.raw.value);
 1232|  2.20k|		sc_pkcs15_free_key_params(&info->params);
 1233|  2.20k|		free(info);
 1234|  2.20k|	}
 1235|  2.20k|}
sc_pkcs15_pubkey_from_spki_fields:
 1326|  2.53k|{
 1327|       |
 1328|  2.53k|	struct sc_pkcs15_pubkey *pubkey = NULL;
 1329|  2.53k|	struct sc_pkcs15_der pk = { NULL, 0 };
 1330|  2.53k|	struct sc_algorithm_id pk_alg;
 1331|  2.53k|	struct sc_asn1_entry asn1_pkinfo[C_ASN1_PKINFO_ATTR_SIZE];
 1332|  2.53k|	unsigned char *tmp_buf = NULL;
 1333|  2.53k|	int r;
 1334|       |
 1335|  2.53k|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1336|  2.53k|	       "sc_pkcs15_pubkey_from_spki_fields() called: %p:%"SC_FORMAT_LEN_SIZE_T"u\n%s",
 1337|  2.53k|	       buf, buflen, sc_dump_hex(buf, buflen));
 1338|       |
 1339|  2.53k|	if (buflen < 1) {
  ------------------
  |  Branch (1339:6): [True: 10, False: 2.52k]
  ------------------
 1340|     10|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "subjectPublicKeyInfo can not be empty");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|     10|	}
 1342|       |
 1343|  2.52k|	tmp_buf = malloc(buflen);
 1344|  2.52k|	if (!tmp_buf) {
  ------------------
  |  Branch (1344:6): [True: 0, False: 2.52k]
  ------------------
 1345|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1346|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1347|      0|	}
 1348|  2.52k|	memcpy(tmp_buf, buf, buflen);
 1349|       |
 1350|  2.52k|	if (buflen > 0 && (*tmp_buf & SC_ASN1_TAG_CONTEXT))
  ------------------
  |  |  187|  2.52k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (1350:6): [True: 2.52k, False: 0]
  |  Branch (1350:20): [True: 133, False: 2.39k]
  ------------------
 1351|    133|		*tmp_buf = SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE;
  ------------------
  |  |  190|    133|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
              		*tmp_buf = SC_ASN1_TAG_CONSTRUCTED | SC_ASN1_TAG_SEQUENCE;
  ------------------
  |  |  206|    133|#define SC_ASN1_TAG_SEQUENCE		16
  ------------------
 1352|       |
 1353|  2.52k|	memset(&pk_alg, 0, sizeof(pk_alg));
 1354|  2.52k|	pubkey = calloc(1, sizeof(sc_pkcs15_pubkey_t));
 1355|  2.52k|	if (pubkey == NULL) {
  ------------------
  |  Branch (1355:6): [True: 0, False: 2.52k]
  ------------------
 1356|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1357|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1358|      0|	}
 1359|       |
 1360|  2.52k|	sc_copy_asn1_entry(c_asn1_pkinfo, asn1_pkinfo);
 1361|       |
 1362|  2.52k|	sc_format_asn1_entry(asn1_pkinfo + 0, &pk_alg, NULL, 0);
 1363|  2.52k|	sc_format_asn1_entry(asn1_pkinfo + 1, &pk.value, &pk.len, 0);
 1364|       |
 1365|  2.52k|	r = sc_asn1_decode(ctx, asn1_pkinfo, tmp_buf, buflen, NULL, NULL);
 1366|  2.52k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.52k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1366:6): [True: 215, False: 2.31k]
  ------------------
 1367|    215|		sc_asn1_clear_algorithm_id(&pk_alg);
 1368|    215|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of subjectPubkeyInfo failed");
  ------------------
  |  |  184|    215|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    215|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    215|	int _ret = (r); \
  |  |  |  |  178|    215|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 215, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    215|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    215|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    215|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    215|		goto err; \
  |  |  |  |  182|    215|	} \
  |  |  |  |  183|    215|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1369|    215|	}
 1370|       |
 1371|  2.31k|	pubkey->alg_id = calloc(1, sizeof(struct sc_algorithm_id));
 1372|  2.31k|	if (pubkey->alg_id == NULL) {
  ------------------
  |  Branch (1372:6): [True: 0, False: 2.31k]
  ------------------
 1373|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1374|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1375|      0|	}
 1376|       |
 1377|  2.31k|	memcpy(pubkey->alg_id, &pk_alg, sizeof(struct sc_algorithm_id));
 1378|  2.31k|	pubkey->algorithm = pk_alg.algorithm;
 1379|  2.31k|	pk_alg.params = NULL;
 1380|  2.31k|	sc_log(ctx, "DEE pk_alg.algorithm=%lu", pk_alg.algorithm);
  ------------------
  |  |   71|  2.31k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1381|       |
 1382|  2.31k|	if (pk.len == 0)
  ------------------
  |  Branch (1382:6): [True: 14, False: 2.29k]
  ------------------
 1383|  2.31k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1384|  2.29k|	pk.len = BYTES4BITS(pk.len); /* convert number of bits to bytes */
  ------------------
  |  |  146|  2.29k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 1385|       |
 1386|  2.29k|	if (pk_alg.algorithm == SC_ALGORITHM_EC)   {
  ------------------
  |  |   79|  2.29k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1386:6): [True: 1.01k, False: 1.28k]
  ------------------
 1387|       |		/* EC public key is not encapsulated into BIT STRING -- it's a BIT STRING */
 1388|       |		/*
 1389|       |		 * sc_pkcs15_fix_ec_parameters below will set field_length from curve.
 1390|       |		 * if no alg_id->params, assume field_length is multiple of 8
 1391|       |		 */
 1392|  1.01k|		pubkey->u.ec.params.field_length = (pk.len - 1) / 2 * 8;
 1393|       |
 1394|  1.01k|		if (pubkey->alg_id->params) {
  ------------------
  |  Branch (1394:7): [True: 1.00k, False: 14]
  ------------------
 1395|  1.00k|			struct sc_ec_parameters *ecp = (struct sc_ec_parameters *)pubkey->alg_id->params;
 1396|       |
 1397|  1.00k|			pubkey->u.ec.params.der.value = malloc(ecp->der.len);
 1398|  1.00k|			if (pubkey->u.ec.params.der.value == NULL) {
  ------------------
  |  Branch (1398:8): [True: 0, False: 1.00k]
  ------------------
 1399|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1400|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1401|      0|			}
 1402|       |
 1403|  1.00k|			memcpy(pubkey->u.ec.params.der.value, ecp->der.value, ecp->der.len);
 1404|  1.00k|			pubkey->u.ec.params.der.len = ecp->der.len;
 1405|  1.00k|			r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
 1406|  1.00k|			LOG_TEST_GOTO_ERR(ctx, r, "failed to fix EC parameters");
  ------------------
  |  |  184|  1.00k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.00k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.00k|	int _ret = (r); \
  |  |  |  |  178|  1.00k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 54, False: 949]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     54|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     54|		goto err; \
  |  |  |  |  182|     54|	} \
  |  |  |  |  183|  1.00k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 949]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1407|  1.00k|		}
 1408|       |
 1409|    963|		pubkey->u.ec.ecpointQ.value = malloc(pk.len);
 1410|    963|		if (pubkey->u.ec.ecpointQ.value == NULL) {
  ------------------
  |  Branch (1410:7): [True: 0, False: 963]
  ------------------
 1411|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1412|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1413|      0|		}
 1414|    963|		memcpy(pubkey->u.ec.ecpointQ.value, pk.value, pk.len);
 1415|    963|		pubkey->u.ec.ecpointQ.len = pk.len;
 1416|  1.28k|	} else if (pk_alg.algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   81|  2.56k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1416:13): [True: 0, False: 1.28k]
  ------------------
 1417|  1.28k|		   pk_alg.algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   82|  1.28k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1417:6): [True: 0, False: 1.28k]
  ------------------
 1418|       |		/*
 1419|       |		 * SPKI will have OID, EDDSA can have ED25519 or ED448 with different sizes
 1420|       |		 * EDDSA/XEDDSA public key is not encapsulated into BIT STRING -- it's a BIT STRING
 1421|       |		 * no params, but oid is the params.
 1422|       |		 */
 1423|      0|		r = sc_encode_oid(ctx, &pk_alg.oid, &pubkey->u.ec.params.der.value, &pubkey->u.ec.params.der.len);
 1424|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1425|      0|		r = sc_pkcs15_fix_ec_parameters(ctx, &pubkey->u.ec.params);
 1426|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1427|       |
 1428|      0|		pubkey->u.ec.ecpointQ.value = malloc(pk.len);
 1429|      0|		if (pubkey->u.ec.ecpointQ.value == NULL) {
  ------------------
  |  Branch (1429:7): [True: 0, False: 0]
  ------------------
 1430|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1431|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1432|      0|		}
 1433|       |
 1434|      0|		memcpy(pubkey->u.ec.ecpointQ.value, pk.value, pk.len);
 1435|      0|		pubkey->u.ec.ecpointQ.len = pk.len;
 1436|  1.28k|	} else {
 1437|       |		/* Public key is expected to be encapsulated into BIT STRING */
 1438|  1.28k|		r = sc_pkcs15_decode_pubkey(ctx, pubkey, pk.value, pk.len);
 1439|  1.28k|		LOG_TEST_GOTO_ERR(ctx, r, "ASN.1 parsing of subjectPubkeyInfo failed");
  ------------------
  |  |  184|  1.28k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.28k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.28k|	int _ret = (r); \
  |  |  |  |  178|  1.28k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 198, False: 1.08k]
  |  |  |  |  ------------------
  |  |  |  |  179|    198|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    198|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    198|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    198|		goto err; \
  |  |  |  |  182|    198|	} \
  |  |  |  |  183|  1.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1440|  1.28k|	}
 1441|       |
 1442|  2.04k|	*outpubkey = pubkey;
 1443|  2.04k|	pubkey = NULL;
 1444|       |
 1445|  2.52k|err:
 1446|  2.52k|	sc_pkcs15_free_pubkey(pubkey);
 1447|  2.52k|	free(pk.value);
 1448|  2.52k|	free(tmp_buf);
 1449|       |
 1450|  2.52k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  2.52k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.52k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.52k|	int _ret = r; \
  |  |  |  |  155|  2.52k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.52k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|    467|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 467, False: 2.06k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.52k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.52k|	return _ret; \
  |  |  |  |  163|  2.52k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1451|  2.52k|}
sc_pkcs15_fix_ec_parameters:
 1565|  4.75k|{
 1566|  4.75k|	int rv, ii;
 1567|  4.75k|	int mapped_string = 0; /* der is printable string that can be replaced with der of OID */
 1568|       |
 1569|  4.75k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.75k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.75k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.75k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.75k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.75k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1570|       |
 1571|       |	/* In PKCS#11 EC parameters arrives in DER encoded form */
 1572|  4.75k|	if (ecparams->der.value && ecparams->der.len && ecparams->der.len > 2) {
  ------------------
  |  Branch (1572:6): [True: 4.75k, False: 0]
  |  Branch (1572:29): [True: 4.75k, False: 0]
  |  Branch (1572:50): [True: 4.75k, False: 0]
  ------------------
 1573|       |
 1574|  4.75k|		switch (ecparams->der.value[0]) {
 1575|  4.74k|		case 0x06: /* der.value is an OID */
  ------------------
  |  Branch (1575:3): [True: 4.74k, False: 10]
  ------------------
 1576|  47.6k|			for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1576:17): [True: 47.5k, False: 44]
  ------------------
 1577|  47.5k|				size_t len = ec_curve_infos[ii].oid_der.len;
 1578|       |
 1579|  47.5k|				if (ecparams->der.len == len &&
  ------------------
  |  Branch (1579:9): [True: 19.0k, False: 28.5k]
  ------------------
 1580|  19.0k|						memcmp(ecparams->der.value, ec_curve_infos[ii].oid_der.value, len) == 0)
  ------------------
  |  Branch (1580:7): [True: 4.70k, False: 14.3k]
  ------------------
 1581|  4.70k|					break; /* found ec_curve_infos[ii] */
 1582|  47.5k|			}
 1583|  4.74k|			break;
 1584|       |
 1585|      0|		case 0x13:
  ------------------
  |  Branch (1585:3): [True: 0, False: 4.75k]
  ------------------
 1586|       |			/* printable string as per PKCS11 V 3.0 for experimental curves */
 1587|      0|			{
 1588|      0|				int r_tag;
 1589|      0|				const u8 *body = ecparams->der.value;
 1590|      0|				size_t len = ecparams->der.len;
 1591|      0|				unsigned int cla_out, tag_out;
 1592|      0|				size_t bodylen;
 1593|       |
 1594|      0|				r_tag = sc_asn1_read_tag(&body, len, &cla_out, &tag_out, &bodylen);
 1595|      0|				if (r_tag != SC_SUCCESS || tag_out != 0x13) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1595:9): [True: 0, False: 0]
  |  Branch (1595:32): [True: 0, False: 0]
  ------------------
 1596|      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__
  |  |  ------------------
  ------------------
 1597|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1598|      0|				}
 1599|      0|				for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1599:18): [True: 0, False: 0]
  ------------------
 1600|      0|					size_t len = strlen(ec_curve_infos[ii].name);
 1601|      0|					if (bodylen != len || memcmp(ec_curve_infos[ii].name, body, len) != 0)
  ------------------
  |  Branch (1601:10): [True: 0, False: 0]
  |  Branch (1601:28): [True: 0, False: 0]
  ------------------
 1602|      0|						continue;
 1603|       |					/* found replacement of printable string to OID */
 1604|      0|					mapped_string = 1;
 1605|      0|					break;
 1606|      0|				}
 1607|      0|			}
 1608|      0|			break;
 1609|       |
 1610|     10|		default:
  ------------------
  |  Branch (1610:3): [True: 10, False: 4.74k]
  ------------------
 1611|     10|			sc_log(ctx, "Unsupported ec params");
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1612|     10|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1613|  4.75k|		}
 1614|       |
 1615|  4.74k|		if (ec_curve_infos[ii].name == NULL) /* end of ec_curve_info */
  ------------------
  |  Branch (1615:7): [True: 44, False: 4.70k]
  ------------------
 1616|  4.74k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported named curve");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1617|       |
 1618|       |		/* ii points to entry with matching oid_der or a mapped entry with replacement oid_der */
 1619|  4.70k|		sc_log(ctx, "Found known curve '%s'", ec_curve_infos[ii].name);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 1620|  4.70k|		if (mapped_string) { /* free previous name if any replace below with new name */
  ------------------
  |  Branch (1620:7): [True: 0, False: 4.70k]
  ------------------
 1621|      0|			free(ecparams->named_curve);
 1622|      0|			ecparams->named_curve = NULL;
 1623|      0|		}
 1624|       |
 1625|  4.70k|		if (!ecparams->named_curve) { /* if present,keep the name as some curves have multiple names */
  ------------------
  |  Branch (1625:7): [True: 3.82k, False: 880]
  ------------------
 1626|  3.82k|			ecparams->named_curve = strdup(ec_curve_infos[ii].name);
 1627|  3.82k|			if (!ecparams->named_curve)
  ------------------
  |  Branch (1627:8): [True: 0, False: 3.82k]
  ------------------
 1628|  3.82k|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1629|       |
 1630|  3.82k|			sc_log(ctx, "Curve name: '%s'", ecparams->named_curve);
  ------------------
  |  |   71|  3.82k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1631|  3.82k|		}
 1632|       |
 1633|       |		/* fill in object_id based on oid_der */
 1634|  4.70k|		sc_format_oid(&ecparams->id, ec_curve_infos[ii].oid_str);
 1635|       |
 1636|  4.70k|		ecparams->field_length = ec_curve_infos[ii].size;
 1637|  4.70k|		ecparams->key_type = ec_curve_infos[ii].key_type;
 1638|  4.70k|		sc_log(ctx, "Curve length %" SC_FORMAT_LEN_SIZE_T "u key_type %d",
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 1639|  4.70k|				ecparams->field_length, ecparams->key_type);
 1640|  4.70k|		if (mapped_string) {
  ------------------
  |  Branch (1640:7): [True: 0, False: 4.70k]
  ------------------
 1641|       |			/* replace the printable string version with the oid */
 1642|      0|			if (ecparams->der.value)
  ------------------
  |  Branch (1642:8): [True: 0, False: 0]
  ------------------
 1643|      0|				free(ecparams->der.value);
 1644|      0|			ecparams->der.len = ec_curve_infos[ii].oid_der.len;
 1645|      0|			ecparams->der.value = malloc(ecparams->der.len);
 1646|      0|			if (ecparams->der.value == NULL) {
  ------------------
  |  Branch (1646:8): [True: 0, False: 0]
  ------------------
 1647|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1648|      0|			}
 1649|      0|			memcpy(ecparams->der.value, ec_curve_infos[ii].oid_der.value, ecparams->der.len);
 1650|      0|		}
 1651|  4.70k|	} else if (ecparams->named_curve) { /* it can be name of curve or OID in ASCII form */
  ------------------
  |  Branch (1651:13): [True: 0, False: 0]
  ------------------
 1652|       |		/* caller did not provide an OID, look for a name or oid_string */
 1653|      0|		for (ii = 0; ec_curve_infos[ii].name; ii++) {
  ------------------
  |  Branch (1653:16): [True: 0, False: 0]
  ------------------
 1654|      0|			if (!strcmp(ec_curve_infos[ii].name, ecparams->named_curve))
  ------------------
  |  Branch (1654:8): [True: 0, False: 0]
  ------------------
 1655|      0|				break;
 1656|      0|			if (!strcmp(ec_curve_infos[ii].oid_str, ecparams->named_curve))
  ------------------
  |  Branch (1656:8): [True: 0, False: 0]
  ------------------
 1657|      0|				break;
 1658|      0|		}
 1659|      0|		if (!ec_curve_infos[ii].name) {
  ------------------
  |  Branch (1659:7): [True: 0, False: 0]
  ------------------
 1660|      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__
  |  |  ------------------
  ------------------
 1661|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1662|      0|		}
 1663|       |
 1664|      0|		rv = sc_format_oid(&ecparams->id, ec_curve_infos[ii].oid_str);
 1665|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1666|       |
 1667|      0|		ecparams->field_length = ec_curve_infos[ii].size;
 1668|      0|		ecparams->key_type = ec_curve_infos[ii].key_type;
 1669|      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__
  |  |  ------------------
  ------------------
 1670|      0|				ecparams->field_length, ecparams->key_type);
 1671|       |
 1672|      0|		if (ecparams->der.value == NULL || ecparams->der.len == 0) {
  ------------------
  |  Branch (1672:7): [True: 0, False: 0]
  |  Branch (1672:38): [True: 0, False: 0]
  ------------------
 1673|      0|			free(ecparams->der.value); /* just in case */
 1674|      0|			ecparams->der.value = NULL;
 1675|      0|			ecparams->der.len = 0;
 1676|       |			/* if caller did not provide valid der OID, fill in */
 1677|      0|			rv = sc_encode_oid (ctx, &ecparams->id, &ecparams->der.value, &ecparams->der.len);
 1678|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1679|      0|		}
 1680|      0|	} else
 1681|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1682|       |
 1683|  4.70k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  4.70k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.70k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.70k|	int _ret = r; \
  |  |  |  |  155|  4.70k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.70k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.70k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4.70k]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.70k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.70k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.70k|	return _ret; \
  |  |  |  |  163|  4.70k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1684|  4.70k|}

sc_pkcs15emu_sc_hsm_decode_cvc:
  433|     90|{
  434|     90|	sc_card_t *card = p15card->card;
  435|     90|	struct sc_asn1_entry asn1_req[C_ASN1_REQ_SIZE];
  436|     90|	struct sc_asn1_entry asn1_authreq[C_ASN1_AUTHREQ_SIZE];
  437|     90|	struct sc_asn1_entry asn1_cvc[C_ASN1_CVC_SIZE];
  438|     90|	struct sc_asn1_entry asn1_cvcert[C_ASN1_CVCERT_SIZE];
  439|     90|	struct sc_asn1_entry asn1_cvc_body[C_ASN1_CVC_BODY_SIZE];
  440|     90|	struct sc_asn1_entry asn1_cvc_pubkey[C_ASN1_CVC_PUBKEY_SIZE];
  441|     90|	unsigned int cla = 0, tag = 0;
  442|     90|	size_t taglen;
  443|     90|	const u8 *tbuf;
  444|     90|	int r;
  445|       |
  446|     90|	memset(cvc, 0, sizeof(*cvc));
  447|     90|	sc_copy_asn1_entry(c_asn1_req, asn1_req);
  448|     90|	sc_copy_asn1_entry(c_asn1_cvc, asn1_cvc);
  449|       |
  450|     90|	r = sc_pkcs15emu_sc_hsm_format_asn1_cvcert(
  451|     90|			asn1_cvcert, C_ASN1_CVCERT_SIZE,
  ------------------
  |  |  242|     90|#define C_ASN1_CVCERT_SIZE 3
  ------------------
  452|     90|			asn1_cvc_body, C_ASN1_CVC_BODY_SIZE,
  ------------------
  |  |  233|     90|#define C_ASN1_CVC_BODY_SIZE 5
  ------------------
  453|     90|			asn1_cvc_pubkey, C_ASN1_CVC_PUBKEY_SIZE,
  ------------------
  |  |  219|     90|#define C_ASN1_CVC_PUBKEY_SIZE 10
  ------------------
  454|     90|			cvc);
  455|     90|	LOG_TEST_RET(card->ctx, r, "sc_asn1_entry array too small");
  ------------------
  |  |  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: 0, False: 90]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     90|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 90]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  456|       |
  457|     90|	sc_format_asn1_entry(asn1_cvc, asn1_cvcert, NULL, 0);
  458|       |
  459|     90|	r = sc_pkcs15emu_sc_hsm_format_asn1_req(
  460|     90|			asn1_authreq, C_ASN1_AUTHREQ_SIZE,
  ------------------
  |  |  255|     90|#define C_ASN1_AUTHREQ_SIZE 4
  ------------------
  461|     90|			asn1_cvcert, cvc);
  462|     90|	LOG_TEST_RET(card->ctx, r, "sc_asn1_entry array too small");
  ------------------
  |  |  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: 0, False: 90]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     90|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 90]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  463|       |
  464|     90|	sc_format_asn1_entry(asn1_req, asn1_authreq, NULL, 0);
  465|       |
  466|       |/*	sc_asn1_print_tags(*buf, *buflen); */
  467|       |
  468|     90|	tbuf = *buf;
  469|     90|	r = sc_asn1_read_tag(&tbuf, *buflen, &cla, &tag, &taglen);
  470|     90|	LOG_TEST_RET(card->ctx, r, "Could not decode card verifiable certificate");
  ------------------
  |  |  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: 44, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  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|     90|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 46]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  471|       |
  472|       |	/*  Determine if we deal with an authenticated request, plain request or certificate */
  473|     46|	if ((cla == (SC_ASN1_TAG_APPLICATION|SC_ASN1_TAG_CONSTRUCTED)) && (tag == 7)) {
  ------------------
  |  |  186|     46|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
              	if ((cla == (SC_ASN1_TAG_APPLICATION|SC_ASN1_TAG_CONSTRUCTED)) && (tag == 7)) {
  ------------------
  |  |  190|     46|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (473:6): [True: 26, False: 20]
  |  Branch (473:68): [True: 3, False: 23]
  ------------------
  474|      3|		r = sc_asn1_decode(card->ctx, asn1_req, *buf, *buflen, buf, buflen);
  475|     43|	} else {
  476|     43|		r = sc_asn1_decode(card->ctx, asn1_cvc, *buf, *buflen, buf, buflen);
  477|     43|	}
  478|       |
  479|     46|	LOG_TEST_RET(card->ctx, r, "Could not decode card verifiable certificate");
  ------------------
  |  |  174|     46|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     46|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     46|	int _ret = (r); \
  |  |  |  |  168|     46|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 46, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     46|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     46|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     46|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     46|		return _ret; \
  |  |  |  |  172|     46|	} \
  |  |  |  |  173|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|     74|{
 1016|     74|	if (cvc->outerSignature) {
  ------------------
  |  Branch (1016:6): [True: 0, False: 74]
  ------------------
 1017|      0|		free(cvc->outerSignature);
 1018|      0|		cvc->outerSignature = NULL;
 1019|      0|	}
 1020|     74|	if (cvc->signature) {
  ------------------
  |  Branch (1020:6): [True: 0, False: 74]
  ------------------
 1021|      0|		free(cvc->signature);
 1022|      0|		cvc->signature = NULL;
 1023|      0|	}
 1024|     74|	if (cvc->primeOrModulus) {
  ------------------
  |  Branch (1024:6): [True: 0, False: 74]
  ------------------
 1025|      0|		free(cvc->primeOrModulus);
 1026|      0|		cvc->primeOrModulus = NULL;
 1027|      0|	}
 1028|     74|	if (cvc->coefficientAorExponent) {
  ------------------
  |  Branch (1028:6): [True: 0, False: 74]
  ------------------
 1029|      0|		free(cvc->coefficientAorExponent);
 1030|      0|		cvc->coefficientAorExponent = NULL;
 1031|      0|	}
 1032|     74|	if (cvc->coefficientB) {
  ------------------
  |  Branch (1032:6): [True: 0, False: 74]
  ------------------
 1033|      0|		free(cvc->coefficientB);
 1034|      0|		cvc->coefficientB = NULL;
 1035|      0|	}
 1036|     74|	if (cvc->basePointG) {
  ------------------
  |  Branch (1036:6): [True: 0, False: 74]
  ------------------
 1037|      0|		free(cvc->basePointG);
 1038|      0|		cvc->basePointG = NULL;
 1039|      0|	}
 1040|     74|	if (cvc->order) {
  ------------------
  |  Branch (1040:6): [True: 0, False: 74]
  ------------------
 1041|      0|		free(cvc->order);
 1042|      0|		cvc->order = NULL;
 1043|      0|	}
 1044|     74|	if (cvc->publicPoint) {
  ------------------
  |  Branch (1044:6): [True: 0, False: 74]
  ------------------
 1045|      0|		free(cvc->publicPoint);
 1046|      0|		cvc->publicPoint = NULL;
 1047|      0|	}
 1048|     74|	if (cvc->cofactor) {
  ------------------
  |  Branch (1048:6): [True: 0, False: 74]
  ------------------
 1049|      0|		free(cvc->cofactor);
 1050|       |		cvc->cofactor = NULL;
 1051|      0|	}
 1052|     74|}
sc_pkcs15emu_sc_hsm_init_ex:
 1602|  10.0k|{
 1603|  10.0k|	if (p15card->card->type != SC_CARD_TYPE_SC_HSM
  ------------------
  |  Branch (1603:6): [True: 10.0k, False: 0]
  ------------------
 1604|  10.0k|			&& p15card->card->type != SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1604:7): [True: 10.0k, False: 0]
  ------------------
 1605|  10.0k|			&& p15card->card->type != SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1605:7): [True: 9.81k, False: 281]
  ------------------
 1606|  9.81k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.81k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1607|  9.81k|	}
 1608|    281|	return sc_pkcs15emu_sc_hsm_init(p15card);
 1609|  10.0k|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_format_asn1_cvcert:
  365|     90|{
  366|     90|	if ((asn1_cvc_pubkey_len < C_ASN1_CVC_PUBKEY_SIZE) ||
  ------------------
  |  |  219|     90|#define C_ASN1_CVC_PUBKEY_SIZE 10
  ------------------
  |  Branch (366:6): [True: 0, False: 90]
  ------------------
  367|     90|		(asn1_cvc_body_len < C_ASN1_CVC_BODY_SIZE) ||
  ------------------
  |  |  233|     90|#define C_ASN1_CVC_BODY_SIZE 5
  ------------------
  |  Branch (367:3): [True: 0, False: 90]
  ------------------
  368|     90|		(asn1_cvcert_len < C_ASN1_CVCERT_SIZE)) {
  ------------------
  |  |  242|     90|#define C_ASN1_CVCERT_SIZE 3
  ------------------
  |  Branch (368:3): [True: 0, False: 90]
  ------------------
  369|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  370|      0|	}
  371|       |
  372|     90|	sc_copy_asn1_entry(c_asn1_cvc_pubkey, asn1_cvc_pubkey);
  373|     90|	sc_copy_asn1_entry(c_asn1_cvc_body, asn1_cvc_body);
  374|     90|	sc_copy_asn1_entry(c_asn1_cvcert, asn1_cvcert);
  375|       |
  376|     90|	sc_format_asn1_entry(asn1_cvc_pubkey    , &cvc->pukoid, NULL, 0);
  377|     90|	sc_format_asn1_entry(asn1_cvc_pubkey + 1, &cvc->primeOrModulus, &cvc->primeOrModuluslen, 0);
  378|     90|	sc_format_asn1_entry(asn1_cvc_pubkey + 2, &cvc->coefficientAorExponent, &cvc->coefficientAorExponentlen, 0);
  379|     90|	sc_format_asn1_entry(asn1_cvc_pubkey + 3, &cvc->coefficientB, &cvc->coefficientBlen, 0);
  380|     90|	sc_format_asn1_entry(asn1_cvc_pubkey + 4, &cvc->basePointG, &cvc->basePointGlen, 0);
  381|     90|	sc_format_asn1_entry(asn1_cvc_pubkey + 5, &cvc->order, &cvc->orderlen, 0);
  382|     90|	sc_format_asn1_entry(asn1_cvc_pubkey + 6, &cvc->publicPoint, &cvc->publicPointlen, 0);
  383|     90|	sc_format_asn1_entry(asn1_cvc_pubkey + 7, &cvc->cofactor, &cvc->cofactorlen, 0);
  384|     90|	sc_format_asn1_entry(asn1_cvc_pubkey + 8, &cvc->modulusSize, NULL, 0);
  385|       |
  386|     90|	sc_format_asn1_entry(asn1_cvc_body    , &cvc->cpi, NULL, 0);
  387|     90|	cvc->carLen = sizeof(cvc->car);
  388|     90|	sc_format_asn1_entry(asn1_cvc_body + 1, &cvc->car, &cvc->carLen, 0);
  389|     90|	sc_format_asn1_entry(asn1_cvc_body + 2, asn1_cvc_pubkey, NULL, 0);
  390|     90|	cvc->chrLen = sizeof(cvc->chr);
  391|     90|	sc_format_asn1_entry(asn1_cvc_body + 3, &cvc->chr, &cvc->chrLen, 0);
  392|       |
  393|     90|	sc_format_asn1_entry(asn1_cvcert    , asn1_cvc_body, NULL, 0);
  394|     90|	sc_format_asn1_entry(asn1_cvcert + 1, &cvc->signature, &cvc->signatureLen, 0);
  395|     90|	return SC_SUCCESS;
  ------------------
  |  |   28|     90|#define SC_SUCCESS				0
  ------------------
  396|     90|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_format_asn1_req:
  413|     90|{
  414|     90|	if (asn1_authreq_len < C_ASN1_AUTHREQ_SIZE) {
  ------------------
  |  |  255|     90|#define C_ASN1_AUTHREQ_SIZE 4
  ------------------
  |  Branch (414:6): [True: 0, False: 90]
  ------------------
  415|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  416|      0|	}
  417|       |
  418|     90|	sc_copy_asn1_entry(c_asn1_authreq, asn1_authreq);
  419|       |
  420|     90|	sc_format_asn1_entry(asn1_authreq    , asn1_cvcert, NULL, 0);
  421|     90|	cvc->outerCARLen = sizeof(cvc->outer_car);
  422|     90|	sc_format_asn1_entry(asn1_authreq + 1, &cvc->outer_car, &cvc->outerCARLen, 0);
  423|     90|	sc_format_asn1_entry(asn1_authreq + 2, &cvc->outerSignature, &cvc->outerSignatureLen, 0);
  424|     90|	return SC_SUCCESS;
  ------------------
  |  |   28|     90|#define SC_SUCCESS				0
  ------------------
  425|     90|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_init:
 1340|    281|{
 1341|    281|	sc_card_t *card = p15card->card;
 1342|    281|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1343|    281|	sc_file_t *file = NULL;
 1344|    281|	sc_path_t path;
 1345|    281|	u8 filelist[MAX_EXT_APDU_LENGTH];
 1346|    281|	int filelistlength;
 1347|    281|	int r, i;
 1348|    281|	sc_cvc_t devcert;
 1349|    281|	struct sc_app_info *appinfo;
 1350|    281|	struct sc_pkcs15_auth_info pin_info;
 1351|    281|	struct sc_pkcs15_object pin_obj;
 1352|    281|	struct sc_pin_cmd_data pindata;
 1353|    281|	u8 efbin[1024];
 1354|    281|	u8 *ptr;
 1355|    281|	size_t len;
 1356|       |
 1357|    281|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    281|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    281|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    281|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    281|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 281]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1358|       |
 1359|    281|	appinfo = calloc(1, sizeof(struct sc_app_info));
 1360|       |
 1361|    281|	if (appinfo == NULL) {
  ------------------
  |  Branch (1361:6): [True: 0, False: 281]
  ------------------
 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|    281|	appinfo->aid = sc_hsm_aid;
 1366|       |
 1367|    281|	appinfo->ddo.aid = sc_hsm_aid;
 1368|    281|	p15card->app = appinfo;
 1369|       |
 1370|    281|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    281|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1371|    281|	r = sc_select_file(card, &path, &file);
 1372|    281|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|    281|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    281|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    281|	int _ret = (r); \
  |  |  |  |  168|    281|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 209, False: 72]
  |  |  |  |  ------------------
  |  |  |  |  169|    209|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    209|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    209|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    209|		return _ret; \
  |  |  |  |  172|    209|	} \
  |  |  |  |  173|    281|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 72]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1373|       |
 1374|     72|	p15card->card->version.hw_major = 24;	/* JCOP 2.4.1r3 */
 1375|     72|	p15card->card->version.hw_minor = 13;
 1376|     72|	if (file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1376:6): [True: 72, False: 0]
  |  Branch (1376:14): [True: 6, False: 66]
  |  Branch (1376:33): [True: 5, False: 1]
  ------------------
 1377|      5|		p15card->card->version.fw_major = file->prop_attr[file->prop_attr_len - 2];
 1378|      5|		p15card->card->version.fw_minor = file->prop_attr[file->prop_attr_len - 1];
 1379|      5|	}
 1380|       |
 1381|     72|	sc_file_free(file);
 1382|       |
 1383|       |	/* Read device certificate to determine serial number */
 1384|     72|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (1384:6): [True: 0, False: 72]
  |  Branch (1384:27): [True: 0, False: 0]
  ------------------
 1385|      0|		ptr = priv->EF_C_DevAut;
 1386|      0|		len = priv->EF_C_DevAut_len;
 1387|     72|	} else {
 1388|     72|		len = sizeof efbin;
 1389|     72|		r = read_file(p15card, (u8 *) "\x2F\x02", efbin, &len, 1);
 1390|     72|		LOG_TEST_RET(card->ctx, r, "Skipping optional EF.C_DevAut");
  ------------------
  |  |  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: 0, False: 72]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     72|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 72]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1391|       |
 1392|     72|		if (len > 0) {
  ------------------
  |  Branch (1392:7): [True: 50, False: 22]
  ------------------
 1393|       |			/* save EF_C_DevAut for further use */
 1394|     50|			ptr = realloc(priv->EF_C_DevAut, len);
 1395|     50|			if (ptr) {
  ------------------
  |  Branch (1395:8): [True: 50, False: 0]
  ------------------
 1396|     50|				memcpy(ptr, efbin, len);
 1397|     50|				priv->EF_C_DevAut = ptr;
 1398|     50|				priv->EF_C_DevAut_len = len;
 1399|     50|			}
 1400|     50|		}
 1401|       |
 1402|     72|		ptr = efbin;
 1403|     72|	}
 1404|       |
 1405|     72|	memset(&devcert, 0 ,sizeof(devcert));
 1406|     72|	r = sc_pkcs15emu_sc_hsm_decode_cvc(p15card, (const u8 **)&ptr, &len, &devcert);
 1407|     72|	LOG_TEST_RET(card->ctx, r, "Could not decode EF.C_DevAut");
  ------------------
  |  |  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: 72, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     72|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     72|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     72|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     72|		return _ret; \
  |  |  |  |  172|     72|	} \
  |  |  |  |  173|     72|} 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);
 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);
 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|     72|{
  294|     72|	sc_path_t path;
  295|     72|	int r;
  296|       |
  297|     72|	sc_path_set(&path, SC_PATH_TYPE_FILE_ID, fid, 2, 0, 0);
  ------------------
  |  |  117|     72|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  298|       |	/* look this up with our AID */
  299|     72|	path.aid = sc_hsm_aid;
  300|       |	/* we don't have a pre-known size of the file */
  301|     72|	path.count = -1;
  302|     72|	if (!p15card->opts.use_file_cache || !efbin
  ------------------
  |  Branch (302:6): [True: 72, False: 0]
  |  Branch (302:39): [True: 0, False: 0]
  ------------------
  303|     72|			|| 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|     72|		path.aid.len = 0;
  306|     72|		r = sc_select_file(p15card->card, &path, NULL);
  307|     72|		if (r < 0) {
  ------------------
  |  Branch (307:7): [True: 15, False: 57]
  ------------------
  308|     15|			sc_log(p15card->card->ctx, "Could not select EF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  309|     57|		} else {
  310|     57|			r = sc_read_binary(p15card->card, 0, efbin, *len, 0);
  311|     57|		}
  312|       |
  313|     72|		if (r < 0) {
  ------------------
  |  Branch (313:7): [True: 20, False: 52]
  ------------------
  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|     52|		} else {
  323|     52|			*len = r;
  324|     52|		}
  325|       |
  326|     72|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (326:7): [True: 0, False: 72]
  ------------------
  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|     72|	}
  332|       |
  333|     72|	return SC_SUCCESS;
  ------------------
  |  |   28|     72|#define SC_SUCCESS				0
  ------------------
  334|     72|}

sc_pkcs15_decipher:
  290|   155k|{
  291|   155k|	sc_context_t *ctx = p15card->card->ctx;
  292|   155k|	int r;
  293|   155k|	sc_algorithm_info_t *alg_info = NULL;
  294|   155k|	sc_security_env_t senv;
  295|   155k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  296|   155k|	unsigned long pad_flags = 0, sec_flags = 0;
  297|       |
  298|   155k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   155k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   155k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   155k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   155k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 155k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|       |
  300|   155k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  306|   155k|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|   155k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (300:6): [True: 93.0k, False: 62.1k]
  ------------------
  301|   155k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for decryption");
  ------------------
  |  |  174|  93.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  93.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  93.0k|	int _ret = (r); \
  |  |  |  |  168|  93.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 93.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  93.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|  93.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  93.0k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  93.0k|		return _ret; \
  |  |  |  |  172|  93.0k|	} \
  |  |  |  |  173|  93.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|       |
  303|  62.1k|	r = format_senv(p15card, obj, &senv, &alg_info);
  304|  62.1k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  62.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  62.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  62.1k|	int _ret = (r); \
  |  |  |  |  168|  62.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 53.4k, False: 8.64k]
  |  |  |  |  ------------------
  |  |  |  |  169|  53.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|  53.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  53.4k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  53.4k|		return _ret; \
  |  |  |  |  172|  53.4k|	} \
  |  |  |  |  173|  62.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8.64k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|  8.64k|	senv.operation = SC_SEC_OPERATION_DECIPHER;
  ------------------
  |  |   56|  8.64k|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  306|       |
  307|  8.64k|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  308|  8.64k|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|  8.64k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  8.64k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  8.64k|	int _ret = (r); \
  |  |  |  |  168|  8.64k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.41k, False: 4.22k]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.41k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.41k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.41k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.41k|		return _ret; \
  |  |  |  |  172|  4.41k|	} \
  |  |  |  |  173|  8.64k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.22k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|  4.22k|	senv.algorithm_flags = sec_flags;
  310|       |
  311|  4.22k|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  312|  4.22k|			outlen);
  313|  4.22k|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|  4.22k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.22k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.22k|	int _ret = (r); \
  |  |  |  |  168|  4.22k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.74k, False: 483]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.74k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.74k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.74k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.74k|		return _ret; \
  |  |  |  |  172|  3.74k|	} \
  |  |  |  |  173|  4.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 483]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  314|       |
  315|       |	/* Strip any padding */
  316|    483|	if (pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) {
  ------------------
  |  |  119|    483|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (316:6): [True: 194, False: 289]
  ------------------
  317|    194|		unsigned int s = r;
  318|    194|		unsigned int key_size = (unsigned int)alg_info->key_length;
  319|    194|		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|    194|	}
  322|    289|#ifdef ENABLE_OPENSSL
  323|    289|	else if (pad_flags & SC_ALGORITHM_RSA_PAD_OAEP) {
  ------------------
  |  |  117|    289|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (323:11): [True: 0, False: 289]
  ------------------
  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|    483|#endif
  341|       |	/* do not log error code to prevent side channel attack */
  342|    483|	return r;
  343|    483|}
sc_pkcs15_derive:
  356|  38.7k|{
  357|  38.7k|	sc_context_t *ctx = p15card->card->ctx;
  358|  38.7k|	int r;
  359|  38.7k|	sc_algorithm_info_t *alg_info = NULL;
  360|  38.7k|	sc_security_env_t senv;
  361|  38.7k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  362|  38.7k|	unsigned long pad_flags = 0, sec_flags = 0;
  363|       |
  364|  38.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  38.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  38.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  38.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  38.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 38.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  365|       |
  366|  38.7k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DERIVE)))
  ------------------
  |  |  313|  38.7k|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  |  Branch (366:6): [True: 21.5k, False: 17.2k]
  ------------------
  367|  38.7k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for derivation");
  ------------------
  |  |  174|  21.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  21.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  21.5k|	int _ret = (r); \
  |  |  |  |  168|  21.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  21.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  21.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  21.5k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  21.5k|		return _ret; \
  |  |  |  |  172|  21.5k|	} \
  |  |  |  |  173|  21.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  368|       |
  369|  17.2k|	switch (obj->type) {
  370|    555|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|    555|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (370:3): [True: 555, False: 16.7k]
  ------------------
  371|    555|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|    555|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (371:3): [True: 0, False: 17.2k]
  ------------------
  372|    555|			if (out == NULL || *poutlen < BYTES4BITS(prkey->field_length)) {
  ------------------
  |  |  146|    555|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  |  Branch (372:8): [True: 0, False: 555]
  |  Branch (372:23): [True: 0, False: 555]
  ------------------
  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|    555|			break;
  378|  16.7k|		default:
  ------------------
  |  Branch (378:3): [True: 16.7k, False: 555]
  ------------------
  379|  16.7k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED,"Key type not supported");
  ------------------
  |  |  174|  16.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  16.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  16.7k|	int _ret = (r); \
  |  |  |  |  168|  16.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  16.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|  16.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  16.7k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  16.7k|		return _ret; \
  |  |  |  |  172|  16.7k|	} \
  |  |  |  |  173|  16.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  380|  17.2k|	}
  381|       |
  382|    555|	r = format_senv(p15card, obj, &senv, &alg_info);
  383|    555|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|    555|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    555|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    555|	int _ret = (r); \
  |  |  |  |  168|    555|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 142, False: 413]
  |  |  |  |  ------------------
  |  |  |  |  169|    142|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    142|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    142|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    142|		return _ret; \
  |  |  |  |  172|    142|	} \
  |  |  |  |  173|    555|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 413]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|    413|	senv.operation = SC_SEC_OPERATION_DERIVE;
  ------------------
  |  |   59|    413|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  385|       |
  386|    413|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  387|    413|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|    413|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    413|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    413|	int _ret = (r); \
  |  |  |  |  168|    413|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 413]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    413|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 413]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  388|    413|	senv.algorithm_flags = sec_flags;
  389|       |
  390|    413|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  391|    413|			*poutlen);
  392|    413|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|    413|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    413|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    413|	int _ret = (r); \
  |  |  |  |  168|    413|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 390, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  169|    390|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    390|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    390|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    390|		return _ret; \
  |  |  |  |  172|    390|	} \
  |  |  |  |  173|    413|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|     23|	*poutlen = r;
  397|     23|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     23|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     23|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     23|	int _ret = r; \
  |  |  |  |  155|     23|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  157|     22|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     22|	} else { \
  |  |  |  |  159|      1|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      1|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      1|	} \
  |  |  |  |  162|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|     23|}
sc_pkcs15_unwrap:
  412|   155k|{
  413|   155k|	sc_context_t *ctx = p15card->card->ctx;
  414|   155k|	int r;
  415|   155k|	sc_algorithm_info_t *alg_info = NULL;
  416|   155k|	sc_security_env_t senv;
  417|   155k|	const struct sc_pkcs15_prkey_info *src_prkey = (const struct sc_pkcs15_prkey_info *) key->data;
  418|   155k|	const struct sc_pkcs15_skey_info *src_skey = (const struct sc_pkcs15_skey_info *) key->data;
  419|   155k|	const struct sc_pkcs15_skey_info *tkey = (const struct sc_pkcs15_skey_info *) target_key->data;
  420|   155k|	unsigned long pad_flags = 0, sec_flags = 0;
  421|   155k|	u8 *out = 0;
  422|   155k|	size_t poutlen = 0;
  423|   155k|	sc_path_t path, target_file_id;
  424|   155k|	sc_sec_env_param_t senv_param;
  425|       |
  426|   155k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   155k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   155k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   155k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   155k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 155k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  427|       |
  428|   155k|	if (key->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|   155k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (428:6): [True: 15.4k, False: 139k]
  ------------------
  429|  15.4k|		if (!(src_prkey->usage & (SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|  15.4k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (429:7): [True: 12.3k, False: 3.03k]
  ------------------
  430|  15.4k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for unwrapping");
  ------------------
  |  |  174|  12.3k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  12.3k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  12.3k|	int _ret = (r); \
  |  |  |  |  168|  12.3k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  12.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|  12.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  12.3k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  12.3k|		return _ret; \
  |  |  |  |  172|  12.3k|	} \
  |  |  |  |  173|  12.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|  15.4k|	}
  432|   139k|	else if ((key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  416|   139k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	else if ((key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  432|   139k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (432:11): [True: 0, False: 139k]
  ------------------
  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|   139k|	else
  437|   139k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|   139k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   139k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   139k|	int _ret = (r); \
  |  |  |  |  168|   139k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 139k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   139k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   139k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   139k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   139k|		return _ret; \
  |  |  |  |  172|   139k|	} \
  |  |  |  |  173|   139k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|       |
  439|  3.03k|	r = format_senv(p15card, key, &senv, &alg_info);
  440|  3.03k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  3.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.03k|	int _ret = (r); \
  |  |  |  |  168|  3.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 204, False: 2.83k]
  |  |  |  |  ------------------
  |  |  |  |  169|    204|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    204|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    204|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    204|		return _ret; \
  |  |  |  |  172|    204|	} \
  |  |  |  |  173|  3.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.83k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  441|  2.83k|	senv.operation = SC_SEC_OPERATION_UNWRAP;
  ------------------
  |  |   61|  2.83k|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  442|       |
  443|  2.83k|	memset(&path, 0, sizeof(sc_path_t));
  444|  2.83k|	memset(&target_file_id, 0, sizeof(sc_path_t));
  445|       |
  446|  2.83k|	if (!tkey->path.len && tkey->path.aid.len) {
  ------------------
  |  Branch (446:6): [True: 2.83k, False: 0]
  |  Branch (446:25): [True: 0, False: 2.83k]
  ------------------
  447|       |		/* Target key is a SDO allocated in application DF */
  448|      0|		target_file_id = tkey->path;
  449|      0|	}
  450|  2.83k|	else if (tkey->path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (450:11): [True: 0, False: 2.83k]
  |  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|  2.83k|	else if (tkey->path.len > 2) {
  ------------------
  |  Branch (457:11): [True: 0, False: 2.83k]
  ------------------
  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|  2.83k|	else {
  464|  2.83k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "invalid unwrapping target key path");
  ------------------
  |  |  174|  2.83k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.83k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.83k|	int _ret = (r); \
  |  |  |  |  168|  2.83k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.83k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.83k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.83k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.83k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.83k|		return _ret; \
  |  |  |  |  172|  2.83k|	} \
  |  |  |  |  173|  2.83k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|  2.83k|	}
  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|   155k|		const u8 *param, size_t paramlen) {
  498|   155k|	sc_context_t *ctx = p15card->card->ctx;
  499|   155k|	int r;
  500|   155k|	sc_algorithm_info_t *alg_info = NULL;
  501|   155k|	sc_security_env_t senv;
  502|   155k|	const struct sc_pkcs15_prkey_info *src_prkey = (const struct sc_pkcs15_prkey_info *) key->data;
  503|   155k|	const struct sc_pkcs15_skey_info *src_skey = (const struct sc_pkcs15_skey_info *) key->data;
  504|   155k|	const struct sc_pkcs15_prkey_info *target_prkey = (const struct sc_pkcs15_prkey_info *) target_key->data;
  505|   155k|	const struct sc_pkcs15_skey_info *target_skey = (const struct sc_pkcs15_skey_info *) target_key->data;
  506|   155k|	unsigned long pad_flags = 0, sec_flags = 0;
  507|   155k|	sc_path_t tkey_path;
  508|   155k|	sc_path_t path, target_file_id;
  509|   155k|	sc_sec_env_param_t senv_param;
  510|       |
  511|   155k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   155k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   155k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   155k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   155k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 155k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  512|       |
  513|   155k|	switch (key->type) {
  514|  15.4k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  15.4k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (514:3): [True: 15.4k, False: 139k]
  ------------------
  515|  15.4k|			if (!(src_prkey->usage & (SC_PKCS15_PRKEY_USAGE_WRAP)))
  ------------------
  |  |  309|  15.4k|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  |  Branch (515:8): [True: 13.7k, False: 1.63k]
  ------------------
  516|  15.4k|				LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for wrapping");
  ------------------
  |  |  174|  13.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  13.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  13.7k|	int _ret = (r); \
  |  |  |  |  168|  13.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  13.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|  13.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  13.7k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  13.7k|		return _ret; \
  |  |  |  |  172|  13.7k|	} \
  |  |  |  |  173|  13.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|  1.63k|			break;
  518|  1.63k|		case SC_PKCS15_TYPE_SKEY_DES:
  ------------------
  |  |  434|      0|#define SC_PKCS15_TYPE_SKEY_DES			0x302
  ------------------
  |  Branch (518:3): [True: 0, False: 155k]
  ------------------
  519|      0|		case SC_PKCS15_TYPE_SKEY_3DES:
  ------------------
  |  |  436|      0|#define SC_PKCS15_TYPE_SKEY_3DES		0x304
  ------------------
  |  Branch (519:3): [True: 0, False: 155k]
  ------------------
  520|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (520:3): [True: 0, False: 155k]
  ------------------
  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|   139k|		default:
  ------------------
  |  Branch (524:3): [True: 139k, False: 15.4k]
  ------------------
  525|   139k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Wrapping key type not supported");
  ------------------
  |  |  174|   139k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   139k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   139k|	int _ret = (r); \
  |  |  |  |  168|   139k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 139k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   139k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   139k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   139k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   139k|		return _ret; \
  |  |  |  |  172|   139k|	} \
  |  |  |  |  173|   139k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  526|   155k|	}
  527|       |
  528|  1.63k|	if (!(target_key->type == SC_PKCS15_TYPE_PRKEY_RSA ||
  ------------------
  |  |  419|  3.26k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (528:8): [True: 0, False: 1.63k]
  ------------------
  529|  1.63k|			(target_key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)) {
  ------------------
  |  |  416|  1.63k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              			(target_key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)) {
  ------------------
  |  |  432|  1.63k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (529:4): [True: 1.63k, 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.63k|	r = format_senv(p15card, key, &senv, &alg_info);
  534|  1.63k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  1.63k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.63k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.63k|	int _ret = (r); \
  |  |  |  |  168|  1.63k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 36, False: 1.59k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.59k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|  1.59k|	senv.operation = SC_SEC_OPERATION_WRAP;
  ------------------
  |  |   60|  1.59k|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  536|       |
  537|  1.59k|	memset(&path, 0, sizeof (sc_path_t));
  538|  1.59k|	memset(&target_file_id, 0, sizeof (sc_path_t));
  539|       |
  540|  1.59k|	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.59k]
  ------------------
  542|      0|			tkey_path = target_prkey->path;
  543|      0|			break;
  544|  1.59k|		default: /* we already know it is a secret key */
  ------------------
  |  Branch (544:3): [True: 1.59k, False: 0]
  ------------------
  545|  1.59k|			tkey_path = target_skey->path;
  546|  1.59k|			break;
  547|  1.59k|	}
  548|       |
  549|  1.59k|	if (!tkey_path.len && tkey_path.aid.len) {
  ------------------
  |  Branch (549:6): [True: 1.59k, False: 0]
  |  Branch (549:24): [True: 0, False: 1.59k]
  ------------------
  550|       |		/* Target key is a SDO allocated in application DF */
  551|      0|		target_file_id = tkey_path;
  552|  1.59k|	} else if (tkey_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (552:13): [True: 0, False: 1.59k]
  |  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.59k|	} else if (tkey_path.len > 2) {
  ------------------
  |  Branch (558:13): [True: 0, False: 1.59k]
  ------------------
  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.59k|	else {
  565|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|  1.59k|	}
  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|   698k|{
  605|   698k|	sc_context_t *ctx = p15card->card->ctx;
  606|   698k|	int r;
  607|   698k|	sc_security_env_t senv;
  608|   698k|	sc_algorithm_info_t *alg_info;
  609|   698k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  610|   698k|	u8 *buf = NULL, *tmp;
  611|   698k|	size_t modlen = 0, buflen = 0;
  612|   698k|	unsigned long pad_flags = 0, sec_flags = 0;
  613|       |
  614|   698k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   698k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   698k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   698k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   698k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 698k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|       |
  616|   698k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  307|   698k|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  308|   698k|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  |  Branch (616:6): [True: 475k, False: 222k]
  ------------------
  617|   698k|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)))
  ------------------
  |  |  314|   698k|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  618|   698k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for signing");
  ------------------
  |  |  174|   475k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   475k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   475k|	int _ret = (r); \
  |  |  |  |  168|   475k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 475k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   475k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   475k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   475k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   475k|		return _ret; \
  |  |  |  |  172|   475k|	} \
  |  |  |  |  173|   475k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|       |
  620|   222k|	r = format_senv(p15card, obj, &senv, &alg_info);
  621|   222k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|   222k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   222k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   222k|	int _ret = (r); \
  |  |  |  |  168|   222k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 173k, False: 49.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|   173k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   173k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   173k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   173k|		return _ret; \
  |  |  |  |  172|   173k|	} \
  |  |  |  |  173|   222k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 49.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  622|  49.8k|	senv.operation = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   57|  49.8k|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  623|       |
  624|  49.8k|	switch (obj->type) {
  625|  44.3k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  44.3k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (625:3): [True: 44.3k, False: 5.49k]
  ------------------
  626|  44.3k|			modlen = BYTES4BITS(prkey->modulus_length);
  ------------------
  |  |  146|  44.3k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  627|  44.3k|			break;
  628|      0|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (628:3): [True: 0, False: 49.8k]
  ------------------
  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|  5.49k|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|  5.49k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (631:3): [True: 5.49k, False: 44.3k]
  ------------------
  632|  5.49k|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|  5.49k|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (632:3): [True: 0, False: 49.8k]
  ------------------
  633|  5.49k|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|  5.49k|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (633:3): [True: 0, False: 49.8k]
  ------------------
  634|  5.49k|			modlen = BYTES4BITS(prkey->field_length) * 2;  /* 2*nLen */
  ------------------
  |  |  146|  5.49k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  635|  5.49k|			break;
  636|      0|		default:
  ------------------
  |  Branch (636:3): [True: 0, False: 49.8k]
  ------------------
  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|  49.8k|	}
  639|       |
  640|       |	/* Probably never happens, but better make sure */
  641|  49.8k|	if (outlen < modlen)
  ------------------
  |  Branch (641:6): [True: 0, False: 49.8k]
  ------------------
  642|  49.8k|		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|  49.8k|	buflen = inlen + modlen;
  645|  49.8k|	buf = sc_mem_secure_alloc(buflen);
  646|  49.8k|	if (buf == NULL)
  ------------------
  |  Branch (646:6): [True: 0, False: 49.8k]
  ------------------
  647|  49.8k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  648|  49.8k|	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|  49.8k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_GOSTR3410) {
  ------------------
  |  |  420|  49.8k|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (653:6): [True: 0, False: 49.8k]
  ------------------
  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|  49.8k|	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|  49.8k|	sc_log(ctx, "supported algorithm flags 0x%lX, private key usage 0x%X", alg_info->flags, prkey->usage);
  ------------------
  |  |   71|  49.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  668|  49.8k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|  49.8k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (668:6): [True: 44.3k, False: 5.49k]
  ------------------
  669|  44.3k|		if ((alg_info->flags & SC_ALGORITHM_NEED_USAGE) &&
  ------------------
  |  |  104|  44.3k|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  |  Branch (669:7): [True: 0, False: 44.3k]
  ------------------
  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|  44.3k|		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  118|  44.3k|#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|  44.3k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (701:7): [True: 0, False: 44.3k]
  ------------------
  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|  44.3k|	}
  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|  49.8k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_EC) {
  ------------------
  |  |  421|  49.8k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (722:6): [True: 5.49k, False: 44.3k]
  ------------------
  723|  5.49k|		if ((alg_info->flags & SC_ALGORITHM_ECDSA_RAW)
  ------------------
  |  |  183|  5.49k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (723:7): [True: 5.49k, False: 0]
  ------------------
  724|  5.49k|				&& !(flags & SC_ALGORITHM_ECDSA_HASHES & alg_info->flags)) {
  ------------------
  |  |  190|  5.49k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  185|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  143|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  191|  5.49k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  186|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  150|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  192|  5.49k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  187|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  193|  5.49k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  188|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  194|  5.49k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  189|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (724:8): [True: 5.49k, False: 0]
  ------------------
  725|  5.49k|			sc_log(ctx, "ECDSA using SC_ALGORITHM_ECDSA_RAW flags before 0x%8.8lx", flags);
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
  726|  5.49k|				flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  183|  5.49k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  727|  5.49k|				flags &= ~SC_ALGORITHM_ECDSA_HASHES;
  ------------------
  |  |  190|  5.49k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  185|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  143|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  191|  5.49k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  186|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  150|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  192|  5.49k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  187|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  193|  5.49k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  188|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  194|  5.49k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  189|  5.49k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  5.49k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  728|  5.49k|		}
  729|  5.49k|	}
  730|       |
  731|  49.8k|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  732|  49.8k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  49.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (732:6): [True: 32.1k, False: 17.6k]
  ------------------
  733|  32.1k|		goto err;
  734|  32.1k|	}
  735|       |	/* senv now has flags card or driver will do */
  736|  17.6k|	senv.algorithm_flags = sec_flags;
  737|       |
  738|  17.6k|	sc_log(ctx, "DEE flags:0x%8.8lx alg_info->flags:0x%8.8lx pad:0x%8.8lx sec:0x%8.8lx",
  ------------------
  |  |   71|  17.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  739|  17.6k|		flags, alg_info->flags, pad_flags, sec_flags);
  740|       |
  741|       |	/* add the padding bytes (if necessary) */
  742|  17.6k|	if (pad_flags != 0) {
  ------------------
  |  Branch (742:6): [True: 6.46k, False: 11.2k]
  ------------------
  743|  6.46k|		size_t tmplen = buflen;
  744|       |
  745|       |		/* XXX Assuming RSA key here */
  746|  6.46k|		r = sc_pkcs1_encode(ctx, pad_flags, tmp, inlen, tmp, &tmplen,
  747|  6.46k|		    prkey->modulus_length, pMechanism);
  748|  6.46k|		LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|  6.46k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  6.46k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  6.46k|	int _ret = (r); \
  |  |  |  |  178|  6.46k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 6.46k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|  6.46k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.46k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  6.46k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  6.46k|		goto err; \
  |  |  |  |  182|  6.46k|	} \
  |  |  |  |  183|  6.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  749|      0|		inlen = tmplen;
  750|      0|	}
  751|  11.2k|	else if ( senv.algorithm == SC_ALGORITHM_RSA &&
  ------------------
  |  |   78|  22.4k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (751:12): [True: 8.77k, False: 2.44k]
  ------------------
  752|  8.77k|	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  112|  8.77k|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
              	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  113|  8.77k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (752:12): [True: 1.30k, False: 7.47k]
  ------------------
  753|       |		/* Add zero-padding if input is shorter than the modulus */
  754|  1.30k|		if (inlen < modlen) {
  ------------------
  |  Branch (754:7): [True: 919, False: 388]
  ------------------
  755|    919|			if (modlen > buflen) {
  ------------------
  |  Branch (755:8): [True: 0, False: 919]
  ------------------
  756|      0|				r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  757|      0|				goto err;
  758|      0|			}
  759|    919|			memmove(tmp+modlen-inlen, tmp, inlen);
  760|    919|			memset(tmp, 0, modlen-inlen);
  761|    919|		}
  762|  1.30k|		inlen = modlen;
  763|  1.30k|	}
  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.91k|	else if (senv.algorithm == SC_ALGORITHM_EC &&
  ------------------
  |  |   79|  19.8k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (770:11): [True: 2.44k, False: 7.47k]
  ------------------
  771|  2.44k|			(senv.algorithm_flags & SC_ALGORITHM_ECDSA_HASHES) == 0) {
  ------------------
  |  |  190|  2.44k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  185|  2.44k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  143|  2.44k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  191|  2.44k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  186|  2.44k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  150|  2.44k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  192|  2.44k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  187|  2.44k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|  2.44k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  193|  2.44k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  188|  2.44k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|  2.44k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  194|  2.44k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  189|  2.44k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  149|  2.44k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (771:4): [True: 2.44k, False: 0]
  ------------------
  772|  2.44k|		inlen = MIN(inlen, BYTES4BITS(prkey->field_length));
  ------------------
  |  |   70|  2.44k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 2.19k, False: 248]
  |  |  ------------------
  ------------------
  773|  2.44k|	}
  774|       |
  775|       |
  776|  11.2k|	r = use_key(p15card, obj, &senv, sc_compute_signature, tmp, inlen,
  777|  11.2k|			out, outlen);
  778|  11.2k|	LOG_TEST_GOTO_ERR(ctx, r, "use_key() failed");
  ------------------
  |  |  184|  11.2k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  11.2k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  11.2k|	int _ret = (r); \
  |  |  |  |  178|  11.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 10.6k, False: 597]
  |  |  |  |  ------------------
  |  |  |  |  179|  10.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|  10.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  10.6k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  10.6k|		goto err; \
  |  |  |  |  182|  10.6k|	} \
  |  |  |  |  183|  11.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 597]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  779|       |
  780|       |	/* Some cards may return RSA signature as integer without leading zero bytes */
  781|       |	/* Already know outlen >= modlen and r >= 0 */
  782|    597|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA && (unsigned)r < modlen) {
  ------------------
  |  |  419|  1.19k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (782:6): [True: 597, False: 0]
  |  Branch (782:47): [True: 486, False: 111]
  ------------------
  783|    486|		memmove(out + modlen - r, out, r);
  784|    486|		memset(out, 0, modlen - r);
  785|    486|		r = (int)modlen;
  786|    486|	}
  787|       |
  788|  49.8k|err:
  789|  49.8k|	sc_mem_secure_clear_free(buf, buflen);
  ------------------
  |  | 1587|  49.8k|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1588|  49.8k|	sc_mem_clear(ptr, len); \
  |  | 1589|  49.8k|	sc_mem_secure_free(ptr, len); \
  |  | 1590|  49.8k|} while (0);
  |  |  ------------------
  |  |  |  Branch (1590:10): [Folded, False: 49.8k]
  |  |  ------------------
  ------------------
  790|       |
  791|  49.8k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  49.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  49.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  49.8k|	int _ret = r; \
  |  |  |  |  155|  49.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49.2k, False: 569]
  |  |  |  |  ------------------
  |  |  |  |  156|  49.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  49.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 49.2k, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  157|  49.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  49.2k|	} else { \
  |  |  |  |  159|    569|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    569|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    569|	} \
  |  |  |  |  162|  49.8k|	return _ret; \
  |  |  |  |  163|  49.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  792|  49.8k|}
pkcs15-sec.c:format_senv:
  175|   290k|{
  176|   290k|	sc_context_t *ctx = p15card->card->ctx;
  177|   290k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  178|   290k|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
  179|       |
  180|   290k|	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|   290k|	memcpy(senv_out->supported_algos, &p15card->tokeninfo->supported_algos, sizeof(senv_out->supported_algos));
  185|       |
  186|   290k|	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  416|   290k|#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|   580k|#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|   212k|#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|   212k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (186:8): [True: 77.7k, False: 212k]
  |  Branch (186:75): [True: 0, False: 212k]
  ------------------
  187|   290k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This is not a private or secret key");
  ------------------
  |  |  174|   212k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   212k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   212k|	int _ret = (r); \
  |  |  |  |  168|   212k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 212k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   212k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   212k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   212k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   212k|		return _ret; \
  |  |  |  |  172|   212k|	} \
  |  |  |  |  173|   212k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* If the key is not native, we can't operate with it. */
  190|  77.7k|	if (!prkey->native)
  ------------------
  |  Branch (190:6): [True: 0, False: 77.7k]
  ------------------
  191|  77.7k|		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|  77.7k|	switch (obj->type) {
  194|  71.1k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  71.1k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (194:3): [True: 71.1k, False: 6.56k]
  ------------------
  195|  71.1k|			*alg_info_out = sc_card_find_rsa_alg(p15card->card, prkey->modulus_length);
  196|  71.1k|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (196:8): [True: 13.7k, False: 57.4k]
  ------------------
  197|  13.7k|				sc_log(ctx,
  ------------------
  |  |   71|  13.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  198|  13.7k|				       "Card does not support RSA with key length %"SC_FORMAT_LEN_SIZE_T"u",
  199|  13.7k|				       prkey->modulus_length);
  200|  13.7k|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|  13.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  13.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  13.7k|	int _ret = r; \
  |  |  |  |  155|  13.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  13.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  13.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  13.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  13.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  13.7k|	return _ret; \
  |  |  |  |  163|  13.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|  13.7k|			}
  202|  57.4k|			senv_out->algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   78|  57.4k|#define SC_ALGORITHM_RSA		0
  ------------------
  203|  57.4k|			senv_out->key_size_bits = prkey->modulus_length;
  204|  57.4k|			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: 77.7k]
  ------------------
  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: 77.7k]
  ------------------
  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: 77.7k]
  ------------------
  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.56k|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|  6.56k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (242:3): [True: 6.56k, False: 71.1k]
  ------------------
  243|  6.56k|			*alg_info_out = sc_card_find_ec_alg(p15card->card, prkey->field_length, NULL);
  244|  6.56k|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (244:8): [True: 664, False: 5.90k]
  ------------------
  245|    664|				sc_log(ctx,
  ------------------
  |  |   71|    664|#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|    664|				       "Card does not support EC with field_size %"SC_FORMAT_LEN_SIZE_T"u",
  247|    664|				       prkey->field_length);
  248|    664|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    664|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    664|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    664|	int _ret = r; \
  |  |  |  |  155|    664|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 664, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    664|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    664|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 664, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    664|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    664|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    664|	return _ret; \
  |  |  |  |  163|    664|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  249|    664|			}
  250|  5.90k|			senv_out->algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   79|  5.90k|#define SC_ALGORITHM_EC		2
  ------------------
  251|  5.90k|			senv_out->key_size_bits = prkey->field_length;
  252|       |
  253|  5.90k|			senv_out->flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   65|  5.90k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  254|  5.90k|			senv_out->algorithm_ref = prkey->field_length;
  255|  5.90k|			break;
  256|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (256:3): [True: 0, False: 77.7k]
  ------------------
  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: 77.7k]
  ------------------
  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|  77.7k|	}
  274|  63.3k|	senv_out->flags |= SC_SEC_ENV_ALG_PRESENT;
  ------------------
  |  |   69|  63.3k|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  275|       |
  276|       |	/* optional keyReference attribute (the default value is -1) */
  277|  63.3k|	if (prkey->key_reference >= 0) {
  ------------------
  |  Branch (277:6): [True: 62.9k, False: 342]
  ------------------
  278|  62.9k|		senv_out->key_ref_len = 1;
  279|  62.9k|		senv_out->key_ref[0] = prkey->key_reference & 0xFF;
  280|  62.9k|		senv_out->flags |= SC_SEC_ENV_KEY_REF_PRESENT;
  ------------------
  |  |   67|  62.9k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  281|  62.9k|	}
  282|       |
  283|  63.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  63.3k|#define SC_SUCCESS				0
  ------------------
  284|  77.7k|}
pkcs15-sec.c:use_key:
  133|  15.8k|{
  134|  15.8k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  15.8k|#define SC_SUCCESS				0
  ------------------
  135|  15.8k|	int revalidated_cached_pin = 0;
  136|  15.8k|	sc_path_t path;
  137|  15.8k|	LOG_TEST_RET(p15card->card->ctx, get_file_path(obj, &path), "Failed to get key file path.");
  ------------------
  |  |  174|  15.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  15.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  15.8k|	int _ret = (r); \
  |  |  |  |  168|  15.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  15.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|       |
  139|  15.8k|	r = sc_lock(p15card->card);
  140|  15.8k|	LOG_TEST_RET(p15card->card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  15.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  15.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  15.8k|	int _ret = (r); \
  |  |  |  |  168|  15.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  15.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|       |
  142|  16.1k|	do {
  143|  16.1k|		if (path.len != 0 || path.aid.len != 0) {
  ------------------
  |  Branch (143:7): [True: 4.08k, False: 12.0k]
  |  Branch (143:24): [True: 406, False: 11.6k]
  ------------------
  144|  4.49k|			r = select_key_file(p15card, obj, senv);
  145|  4.49k|			if (r < 0) {
  ------------------
  |  Branch (145:8): [True: 2.85k, False: 1.63k]
  ------------------
  146|  2.85k|				sc_log(p15card->card->ctx,
  ------------------
  |  |   71|  2.85k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  147|  2.85k|						"Unable to select private key file");
  148|  2.85k|			}
  149|  4.49k|		}
  150|  16.1k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (150:7): [True: 13.2k, False: 2.85k]
  ------------------
  151|  13.2k|			r = sc_set_security_env(p15card->card, senv, 0);
  152|       |
  153|  16.1k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (153:7): [True: 8.92k, False: 7.20k]
  ------------------
  154|  8.92k|			r = card_command(p15card->card, in, inlen, out, outlen);
  155|       |
  156|  16.1k|		if (revalidated_cached_pin)
  ------------------
  |  Branch (156:7): [True: 276, False: 15.8k]
  ------------------
  157|       |			/* only re-validate once */
  158|    276|			break;
  159|  15.8k|		if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|  15.8k|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (159:7): [True: 381, False: 15.4k]
  ------------------
  160|    381|			r = sc_pkcs15_pincache_revalidate(p15card, obj);
  161|    381|			if (r < 0)
  ------------------
  |  Branch (161:8): [True: 105, False: 276]
  ------------------
  162|    105|				break;
  163|    276|			revalidated_cached_pin = 1;
  164|    276|		}
  165|  15.8k|	} while (revalidated_cached_pin);
  ------------------
  |  Branch (165:11): [True: 276, False: 15.4k]
  ------------------
  166|       |
  167|  15.8k|	sc_unlock(p15card->card);
  168|       |
  169|  15.8k|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|  15.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  15.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  15.8k|	int _ret = r; \
  |  |  |  |  155|  15.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15.1k, False: 672]
  |  |  |  |  ------------------
  |  |  |  |  156|  15.1k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  14.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14.7k, False: 431]
  |  |  |  |  ------------------
  |  |  |  |  157|  15.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  15.1k|	} else { \
  |  |  |  |  159|    672|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    672|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    672|	} \
  |  |  |  |  162|  15.8k|	return _ret; \
  |  |  |  |  163|  15.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|  15.8k|}
pkcs15-sec.c:get_file_path:
   57|  20.3k|{
   58|  20.3k|	if (!path)
  ------------------
  |  Branch (58:6): [True: 0, False: 20.3k]
  ------------------
   59|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   60|       |
   61|  20.3k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
   62|  20.3k|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
   63|       |
   64|  20.3k|	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  416|  20.3k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  418|  20.3k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (64:6): [True: 20.3k, False: 0]
  ------------------
   65|  20.3k|		*path = prkey->path;
   66|  20.3k|	}
   67|      0|	else if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  416|      0|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	else if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (67:11): [True: 0, False: 0]
  ------------------
   68|      0|		*path = skey->path;
   69|      0|	}
   70|      0|	else
   71|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   72|       |
   73|  20.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  20.3k|#define SC_SUCCESS				0
  ------------------
   74|  20.3k|}
pkcs15-sec.c:select_key_file:
   80|  4.49k|{
   81|  4.49k|	sc_context_t *ctx = p15card->card->ctx;
   82|  4.49k|	sc_path_t orig_path;
   83|  4.49k|	sc_path_t path, file_id;
   84|  4.49k|	int r;
   85|       |
   86|  4.49k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.49k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.49k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.49k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.49k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.49k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   87|       |
   88|  4.49k|	LOG_TEST_RET(ctx, get_file_path(key, &orig_path), "Could not get key file path.");
  ------------------
  |  |  174|  4.49k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.49k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.49k|	int _ret = (r); \
  |  |  |  |  168|  4.49k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 4.49k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.49k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|  4.49k|	memset(&path, 0, sizeof(sc_path_t));
   90|  4.49k|	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.49k|	if (!orig_path.len && orig_path.aid.len) {
  ------------------
  |  Branch (96:6): [True: 406, False: 4.08k]
  |  Branch (96:24): [True: 406, False: 0]
  ------------------
   97|       |		/* Private key is a SDO allocated in application DF */
   98|    406|		path = orig_path;
   99|    406|	}
  100|  4.08k|	else if (orig_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (100:11): [True: 0, False: 4.08k]
  |  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|  4.08k|	else if (orig_path.len > 2) {
  ------------------
  |  Branch (108:11): [True: 4.08k, False: 0]
  ------------------
  109|  4.08k|		path = orig_path;
  110|  4.08k|		memcpy(file_id.value, orig_path.value + orig_path.len - 2, 2);
  111|  4.08k|		file_id.len = 2;
  112|  4.08k|		file_id.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  4.08k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  113|  4.08k|		senv->file_ref = file_id;
  114|  4.08k|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   66|  4.08k|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  115|  4.08k|	}
  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.49k|	r = sc_select_file(p15card->card, &path, NULL);
  121|  4.49k|	LOG_TEST_RET(ctx, r, "sc_select_file() failed");
  ------------------
  |  |  174|  4.49k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.49k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.49k|	int _ret = (r); \
  |  |  |  |  168|  4.49k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.85k, False: 1.63k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.85k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.85k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.85k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.85k|		return _ret; \
  |  |  |  |  172|  2.85k|	} \
  |  |  |  |  173|  4.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|  1.63k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.63k|	int _ret = r; \
  |  |  |  |  155|  1.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.63k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.63k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.63k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.63k|	return _ret; \
  |  |  |  |  163|  1.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|  1.63k|}

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

sc_pkcs15emu_starcert_init_ex:
  274|  13.0k|{
  275|  13.0k|	if (starcert_detect_card(p15card))
  ------------------
  |  Branch (275:6): [True: 12.9k, False: 86]
  ------------------
  276|  12.9k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  12.9k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  277|     86|	return sc_pkcs15emu_starcert_init(p15card);
  278|  13.0k|}
pkcs15-starcert.c:starcert_detect_card:
  101|  13.0k|{
  102|  13.0k|	int       r;
  103|  13.0k|	u8        buf[128];
  104|  13.0k|	sc_path_t path;
  105|  13.0k|	sc_card_t *card = p15card->card;
  106|       |
  107|       |	/* check if we have the correct card OS */
  108|  13.0k|	if (strcmp(card->name, "STARCOS"))
  ------------------
  |  Branch (108:6): [True: 12.8k, False: 207]
  ------------------
  109|  12.8k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  12.8k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  110|       |	/* read EF_Info file */
  111|    207|	sc_format_path("3F00FE13", &path);
  112|    207|	r = sc_select_file(card, &path, NULL);
  113|    207|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    207|#define SC_SUCCESS				0
  ------------------
  |  Branch (113:6): [True: 107, False: 100]
  ------------------
  114|    107|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    107|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  115|    100|	r = sc_read_binary(card, 0, buf, 64, 0);
  116|    100|	if (r != 64)
  ------------------
  |  Branch (116:6): [True: 8, False: 92]
  ------------------
  117|      8|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      8|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  118|     92|	if (memcmp(buf + 24, STARCERT, strlen(STARCERT)))
  ------------------
  |  |   35|     92|#define STARCERT	"StarCertV2201"
  ------------------
              	if (memcmp(buf + 24, STARCERT, strlen(STARCERT)))
  ------------------
  |  |   35|     92|#define STARCERT	"StarCertV2201"
  ------------------
  |  Branch (118:6): [True: 6, False: 86]
  ------------------
  119|      6|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      6|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  120|       |
  121|     86|	return SC_SUCCESS;
  ------------------
  |  |   28|     86|#define SC_SUCCESS				0
  ------------------
  122|     92|}
pkcs15-starcert.c:sc_pkcs15emu_starcert_init:
  125|     86|{
  126|     86|	const cdata certs[] = {
  127|     86|		{"DS certificate", 0, "3F00DF01C000","1",
  128|     86|			SC_PKCS15_CO_FLAG_MODIFIABLE},
  ------------------
  |  |   51|     86|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  129|     86|		{"CA certificate", 1, "3F00DF01C008","2",
  130|     86|			SC_PKCS15_CO_FLAG_MODIFIABLE},
  ------------------
  |  |   51|     86|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  131|     86|		{"KE certificate", 0, "3F00DF01C200","3",
  132|     86|			SC_PKCS15_CO_FLAG_MODIFIABLE},
  ------------------
  |  |   51|     86|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  133|     86|		{"AUT certificate",0, "3F00DF01C500","4",
  134|     86|			SC_PKCS15_CO_FLAG_MODIFIABLE},
  ------------------
  |  |   51|     86|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  135|     86|		{NULL, 0, NULL, NULL, 0}
  136|     86|	};
  137|       |
  138|     86|	const pindata pins[] = {
  139|     86|		{ "99", "DS pin", "3F00DF01", 0x99,
  140|     86|		  SC_PKCS15_PIN_TYPE_ASCII_NUMERIC,
  ------------------
  |  |   89|     86|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  141|     86|		  8, 8, 8, SC_PKCS15_PIN_FLAG_NEEDS_PADDING |
  ------------------
  |  |   59|     86|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  142|     86|		  SC_PKCS15_PIN_FLAG_LOCAL, -1, 0x00,
  ------------------
  |  |   55|     86|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  143|     86|		  SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE },
  ------------------
  |  |   51|     86|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              		  SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE },
  ------------------
  |  |   50|     86|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  144|     86|		{ NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  145|     86|	};
  146|       |
  147|     86|	const prdata prkeys[] = {
  148|     86|		{ "01", "DS key", 1024, USAGE_NONREP, "3F00DF01",
  ------------------
  |  |   71|     86|#define USAGE_NONREP	SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  |  |  ------------------
  |  |  |  |  314|     86|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  |  |  ------------------
  ------------------
  149|     86|		  0x84, "99", SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|     86|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  150|     86|		{ "03", "KE key", 1024, USAGE_KE, "3F00DF01",
  ------------------
  |  |   72|     86|#define USAGE_KE	SC_PKCS15_PRKEY_USAGE_ENCRYPT | \
  |  |  ------------------
  |  |  |  |  305|     86|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   73|     86|			SC_PKCS15_PRKEY_USAGE_DECRYPT | \
  |  |  ------------------
  |  |  |  |  306|     86|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   74|     86|			SC_PKCS15_PRKEY_USAGE_WRAP    | \
  |  |  ------------------
  |  |  |  |  309|     86|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  |  |   75|     86|			SC_PKCS15_PRKEY_USAGE_UNWRAP
  |  |  ------------------
  |  |  |  |  310|     86|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
  151|     86|		  0x85, NULL, SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|     86|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  152|     86|		{ "04", "AUT key", 1024, USAGE_AUT, "3F00DF01",
  ------------------
  |  |   76|     86|#define USAGE_AUT	SC_PKCS15_PRKEY_USAGE_ENCRYPT | \
  |  |  ------------------
  |  |  |  |  305|     86|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   77|     86|			SC_PKCS15_PRKEY_USAGE_DECRYPT | \
  |  |  ------------------
  |  |  |  |  306|     86|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   78|     86|			SC_PKCS15_PRKEY_USAGE_WRAP    | \
  |  |  ------------------
  |  |  |  |  309|     86|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  |  |   79|     86|			SC_PKCS15_PRKEY_USAGE_UNWRAP  | \
  |  |  ------------------
  |  |  |  |  310|     86|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  |  |   80|     86|			SC_PKCS15_PRKEY_USAGE_SIGN
  |  |  ------------------
  |  |  |  |  307|     86|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  |  |  ------------------
  ------------------
  153|     86|		  0x82, NULL, SC_PKCS15_CO_FLAG_PRIVATE},
  ------------------
  |  |   50|     86|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  154|     86|		{ NULL, NULL, 0, 0, NULL, 0, NULL, 0}
  155|     86|	};
  156|       |
  157|     86|	int    r, i;
  158|     86|	char   buf[256];
  159|     86|	sc_path_t path;
  160|     86|	sc_file_t *file = NULL;
  161|     86|	sc_card_t *card = p15card->card;
  162|     86|	sc_serial_number_t serial;
  163|       |
  164|       |	/* get serial number */
  165|     86|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  166|     86|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     86|#define SC_SUCCESS				0
  ------------------
  |  Branch (166:6): [True: 5, False: 81]
  ------------------
  167|      5|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      5|#define SC_ERROR_INTERNAL			-1400
  ------------------
  168|     81|	r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
  169|     81|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     81|#define SC_SUCCESS				0
  ------------------
  |  Branch (169:6): [True: 0, False: 81]
  ------------------
  170|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  171|       |
  172|     81|	set_string(&p15card->tokeninfo->serial_number, buf);
  173|     81|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (173:6): [True: 0, False: 81]
  ------------------
  174|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  175|       |	/* the manufacturer ID, in this case Giesecke & Devrient GmbH */
  176|     81|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   34|     81|#define MANU_ID		"Giesecke & Devrient GmbH"
  ------------------
  177|     81|	if (!p15card->tokeninfo->manufacturer_id)
  ------------------
  |  Branch (177:6): [True: 0, False: 81]
  ------------------
  178|      0|		goto err;
  179|       |
  180|       |	/* set certs */
  181|    405|	for (i = 0; certs[i].label; i++) {
  ------------------
  |  Branch (181:14): [True: 324, False: 81]
  ------------------
  182|    324|		struct sc_pkcs15_cert_info cert_info;
  183|    324|		struct sc_pkcs15_object    cert_obj;
  184|       |
  185|    324|		memset(&cert_info, 0, sizeof(cert_info));
  186|    324|		memset(&cert_obj,  0, sizeof(cert_obj));
  187|       |
  188|    324|		sc_pkcs15_format_id(certs[i].id, &cert_info.id);
  189|    324|		cert_info.authority = certs[i].authority;
  190|    324|		sc_format_path(certs[i].path, &cert_info.path);
  191|    324|		if (!get_cert_len(card, &cert_info.path))
  ------------------
  |  Branch (191:7): [True: 323, False: 1]
  ------------------
  192|       |			/* skip errors */
  193|    323|			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|    162|	for (i = 0; pins[i].label; i++) {
  ------------------
  |  Branch (203:14): [True: 81, False: 81]
  ------------------
  204|     81|		struct sc_pkcs15_auth_info pin_info;
  205|     81|		struct sc_pkcs15_object   pin_obj;
  206|       |
  207|     81|		memset(&pin_info, 0, sizeof(pin_info));
  208|     81|		memset(&pin_obj,  0, sizeof(pin_obj));
  209|       |
  210|       |
  211|     81|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
  212|     81|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     81|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  213|     81|		pin_info.attrs.pin.reference     = pins[i].ref;
  214|     81|		pin_info.attrs.pin.flags         = pins[i].flags;
  215|     81|		pin_info.attrs.pin.type          = pins[i].type;
  216|     81|		pin_info.attrs.pin.min_length    = pins[i].minlen;
  217|     81|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
  218|     81|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
  219|     81|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
  220|     81|		sc_format_path(pins[i].path, &pin_info.path);
  221|     81|		pin_info.tries_left    = -1;
  222|     81|		pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|     81|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  223|       |
  224|     81|		strlcpy(pin_obj.label, pins[i].label, sizeof(pin_obj.label));
  ------------------
  |  |   43|     81|#define strlcpy _strlcpy
  ------------------
  225|     81|		pin_obj.flags = pins[i].obj_flags;
  226|       |
  227|     81|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  228|     81|		if (r < 0)
  ------------------
  |  Branch (228:7): [True: 0, False: 81]
  ------------------
  229|      0|			goto err;
  230|     81|	}
  231|       |	/* set private keys */
  232|    324|	for (i = 0; prkeys[i].label; i++) {
  ------------------
  |  Branch (232:14): [True: 243, False: 81]
  ------------------
  233|    243|		struct sc_pkcs15_prkey_info prkey_info;
  234|    243|		struct sc_pkcs15_object     prkey_obj;
  235|       |
  236|    243|		memset(&prkey_info, 0, sizeof(prkey_info));
  237|    243|		memset(&prkey_obj,  0, sizeof(prkey_obj));
  238|       |
  239|    243|		sc_pkcs15_format_id(prkeys[i].id, &prkey_info.id);
  240|    243|		prkey_info.usage         = prkeys[i].usage;
  241|    243|		prkey_info.native        = 1;
  242|    243|		prkey_info.key_reference = prkeys[i].ref;
  243|    243|		prkey_info.modulus_length= prkeys[i].modulus_len;
  244|    243|		sc_format_path(prkeys[i].path, &prkey_info.path);
  245|       |
  246|    243|		strlcpy(prkey_obj.label, prkeys[i].label, sizeof(prkey_obj.label));
  ------------------
  |  |   43|    243|#define strlcpy _strlcpy
  ------------------
  247|    243|		prkey_obj.flags = prkeys[i].obj_flags;
  248|    243|		if (prkeys[i].auth_id)
  ------------------
  |  Branch (248:7): [True: 81, False: 162]
  ------------------
  249|     81|			sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
  250|       |
  251|    243|		r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  252|    243|		if (r < 0)
  ------------------
  |  Branch (252:7): [True: 0, False: 243]
  ------------------
  253|      0|			goto err;
  254|    243|	}
  255|       |
  256|       |	/* select the application DF */
  257|     81|	sc_format_path("3F00DF01", &path);
  258|     81|	r = sc_select_file(card, &path, &file);
  259|     81|	if (r != SC_SUCCESS || !file)
  ------------------
  |  |   28|    162|#define SC_SUCCESS				0
  ------------------
  |  Branch (259:6): [True: 17, False: 64]
  |  Branch (259:25): [True: 0, False: 64]
  ------------------
  260|     17|		goto err;
  261|       |	/* set the application DF */
  262|     64|	sc_file_free(p15card->file_app);
  263|     64|	p15card->file_app = file;
  264|       |
  265|     64|	return SC_SUCCESS;
  ------------------
  |  |   28|     64|#define SC_SUCCESS				0
  ------------------
  266|       |
  267|     17|err:
  268|     17|	sc_pkcs15_card_clear(p15card);
  269|     17|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     17|#define SC_ERROR_INTERNAL			-1400
  ------------------
  270|     81|}
pkcs15-starcert.c:get_cert_len:
   83|    324|{
   84|    324|	int r;
   85|    324|	u8  buf[8];
   86|       |
   87|    324|	r = sc_select_file(card, path, NULL);
   88|    324|	if (r < 0)
  ------------------
  |  Branch (88:6): [True: 300, False: 24]
  ------------------
   89|    300|		return 0;
   90|     24|	r = sc_read_binary(card, 0, buf, sizeof(buf), 0);
   91|     24|	if (r < 4)
  ------------------
  |  Branch (91:6): [True: 10, False: 14]
  ------------------
   92|     10|		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.59k|{
  356|  7.59k|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.59k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  357|       |
  358|  7.59k|	if (!p15card || !p15card->card || !p15card->card->ctx)
  ------------------
  |  Branch (358:6): [True: 0, False: 7.59k]
  |  Branch (358:18): [True: 0, False: 7.59k]
  |  Branch (358:36): [True: 0, False: 7.59k]
  ------------------
  359|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  360|       |
  361|  7.59k|	r = starcos_esign_init(p15card, aid);
  362|  7.59k|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|  7.59k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.59k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.59k|	int _ret = r; \
  |  |  |  |  155|  7.59k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.59k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.59k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.53k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.53k, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.59k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.59k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.59k|	return _ret; \
  |  |  |  |  163|  7.59k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|  7.59k|}
pkcs15-starcos-esign.c:starcos_esign_init:
  286|  7.59k|{
  287|  7.59k|	sc_card_t *card = p15card->card;
  288|  7.59k|	sc_context_t *ctx = card->ctx;
  289|  7.59k|	const char *label = name_Card;
  290|  7.59k|	int r;
  291|  7.59k|	int apps_added = 0;
  292|       |
  293|  7.59k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  7.59k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.59k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.59k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.59k]
  |  |  ------------------
  ------------------
  294|       |
  295|  7.59k|	if (card->type != SC_CARD_TYPE_STARCOS_V3_4_ESIGN && card->type != SC_CARD_TYPE_STARCOS_V3_5_ESIGN) {
  ------------------
  |  Branch (295:6): [True: 7.49k, False: 102]
  |  Branch (295:55): [True: 7.49k, False: 0]
  ------------------
  296|  7.49k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.49k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  297|  7.49k|	}
  298|       |
  299|    102|	if (aid == NULL) {
  ------------------
  |  Branch (299:6): [True: 102, False: 0]
  ------------------
  300|       |		// no aid: in this case all emulated apps are added, currently only the esign_app
  301|    102|		r = starcos_add_esign_app(p15card);
  302|    102|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|    102|#define SC_SUCCESS				0
  ------------------
  |  Branch (302:7): [True: 74, False: 28]
  ------------------
  303|     74|			apps_added++;
  304|    102|	} 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|    102|	if (apps_added == 0) {
  ------------------
  |  Branch (327:6): [True: 28, False: 74]
  ------------------
  328|     28|		LOG_TEST_RET(ctx, SC_ERROR_WRONG_CARD, "No supported app found on this card");
  ------------------
  |  |  174|     28|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     28|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     28|	int _ret = (r); \
  |  |  |  |  168|     28|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     28|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     28|		return _ret; \
  |  |  |  |  172|     28|	} \
  |  |  |  |  173|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  329|     28|	}
  330|       |
  331|     74|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  332|       |
  333|     74|	p15card->tokeninfo = sc_pkcs15_tokeninfo_new();
  334|     74|	if (!p15card->tokeninfo) {
  ------------------
  |  Branch (334:6): [True: 0, False: 74]
  ------------------
  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|     74|	} else {
  337|     74|		sc_serial_number_t serial;
  338|     74|		char serial_hex[SC_MAX_SERIALNR * 2 + 2];
  339|     74|		r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
  340|     74|		LOG_TEST_RET(ctx, r, "Failed to query card serial number");
  ------------------
  |  |  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: 10, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  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|     74|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  341|       |
  342|     64|		r = sc_bin_to_hex(serial.value, serial.len, serial_hex, sizeof serial_hex, 0);
  343|     64|		LOG_TEST_RET(ctx, r, "Failed to convert S/N to hex");
  ------------------
  |  |  174|     64|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     64|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     64|	int _ret = (r); \
  |  |  |  |  168|     64|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  344|     64|		p15card->tokeninfo->serial_number = strdup(serial_hex);
  345|     64|		p15card->tokeninfo->label = strdup(label);
  346|     64|		p15card->tokeninfo->manufacturer_id = strdup(name_Vendor);
  347|     64|		p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|     64|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  348|     64|	}
  349|       |
  350|     64|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     64|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     64|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     64|	int _ret = r; \
  |  |  |  |  155|     64|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     64|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  157|     64|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     64|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     64|	return _ret; \
  |  |  |  |  163|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|     64|}
pkcs15-starcos-esign.c:starcos_add_esign_app:
  253|    102|{
  254|    102|	static cdata auth_cert = {"C.CH.AUT", 0, "3F00060843F1", "1", 0};
  255|    102|	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|    102|	static prdata auth_key = {"1", "PrK.CH.AUT", 2048, USAGE_AUT, "3F000608", 0x81, "1", SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   89|    102|#define USAGE_AUT SC_PKCS15_PRKEY_USAGE_ENCRYPT | \
  |  |  ------------------
  |  |  |  |  305|    102|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   90|    102|				  SC_PKCS15_PRKEY_USAGE_DECRYPT | \
  |  |  ------------------
  |  |  |  |  306|    102|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   91|    102|				  SC_PKCS15_PRKEY_USAGE_WRAP | \
  |  |  ------------------
  |  |  |  |  309|    102|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  |  |   92|    102|				  SC_PKCS15_PRKEY_USAGE_UNWRAP | \
  |  |  ------------------
  |  |  |  |  310|    102|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  |  |   93|    102|				  SC_PKCS15_PRKEY_USAGE_SIGN
  |  |  ------------------
  |  |  |  |  307|    102|#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|    102|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  262|    102|	static prdata encr_key = {"2", "PrK.CH.ENC", 2048, USAGE_KE, "3F000608", 0x83, "1", SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   85|    102|#define USAGE_KE     SC_PKCS15_PRKEY_USAGE_ENCRYPT | \
  |  |  ------------------
  |  |  |  |  305|    102|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   86|    102|				 SC_PKCS15_PRKEY_USAGE_DECRYPT | \
  |  |  ------------------
  |  |  |  |  306|    102|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   87|    102|				 SC_PKCS15_PRKEY_USAGE_WRAP | \
  |  |  ------------------
  |  |  |  |  309|    102|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  |  |   88|    102|				 SC_PKCS15_PRKEY_USAGE_UNWRAP
  |  |  ------------------
  |  |  |  |  310|    102|#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|    102|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  263|       |
  264|    102|	static pindata auth_pin = {"1", "UserPIN", "3F00", 0x01, SC_PKCS15_PIN_TYPE_UTF8, 16, 6, 0,
  ------------------
  |  |   90|    102|#define SC_PKCS15_PIN_TYPE_UTF8				2
  ------------------
  265|    102|			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   94|    102|#define USER_PIN  SC_PKCS15_PIN_FLAG_INITIALIZED | \
  |  |  ------------------
  |  |  |  |   58|    102|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   95|    102|				SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | \
  |  |  ------------------
  |  |  |  |   54|    102|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  |  |  ------------------
  |  |   96|    102|				SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL | \
  |  |  ------------------
  |  |  |  |   75|    102|	( SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|    102|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   97|    102|				SC_PKCS15_PIN_AUTH_TYPE_PIN
  |  |  ------------------
  |  |  |  |   94|    102|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  |  |  ------------------
  ------------------
              			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   51|    102|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|    102|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  266|       |
  267|    102|	static pindata auth_pin_v35 = {"1", "UserPIN", "3F00", 0x06, SC_PKCS15_PIN_TYPE_UTF8, 16, 6, 0,
  ------------------
  |  |   90|    102|#define SC_PKCS15_PIN_TYPE_UTF8				2
  ------------------
  268|    102|			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   94|    102|#define USER_PIN  SC_PKCS15_PIN_FLAG_INITIALIZED | \
  |  |  ------------------
  |  |  |  |   58|    102|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  ------------------
  |  |   95|    102|				SC_PKCS15_PIN_FLAG_CASE_SENSITIVE | \
  |  |  ------------------
  |  |  |  |   54|    102|#define SC_PKCS15_PIN_FLAG_CASE_SENSITIVE		0x0001
  |  |  ------------------
  |  |   96|    102|				SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL | \
  |  |  ------------------
  |  |  |  |   75|    102|	( SC_PKCS15_PIN_FLAG_INITIALIZED )
  |  |  |  |  ------------------
  |  |  |  |  |  |   58|    102|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   97|    102|				SC_PKCS15_PIN_AUTH_TYPE_PIN
  |  |  ------------------
  |  |  |  |   94|    102|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  |  |  ------------------
  ------------------
              			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   51|    102|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              			USER_PIN, -1, 3, 0x00, SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|    102|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  269|       |
  270|    102|	ppindata auth = (p15card->card->type == SC_CARD_TYPE_STARCOS_V3_5_ESIGN) ? &auth_pin_v35 : &auth_pin;
  ------------------
  |  Branch (270:18): [True: 0, False: 102]
  ------------------
  271|       |
  272|    102|	const container containers[] = {
  273|    102|			{"1", &auth_cert, auth, &auth_key},
  274|    102|			{"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|    102|	};
  280|       |
  281|    102|	return add_app(p15card, containers, sizeof(containers) / sizeof(container));
  282|    102|}
pkcs15-starcos-esign.c:add_app:
  116|    102|{
  117|    102|	int i, containers_added = 0, r = SC_SUCCESS;
  ------------------
  |  |   28|    102|#define SC_SUCCESS				0
  ------------------
  118|    102|	ppindata installed_pins[4];
  119|    102|	size_t installed_pin_count = 0;
  120|    102|	sc_card_t *card = p15card->card;
  121|       |
  122|    102|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    102|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    102|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    102|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    102|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 102]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  123|       |
  124|    306|	for (i = 0; i < container_count; i++) {
  ------------------
  |  Branch (124:14): [True: 204, False: 102]
  ------------------
  125|    204|		struct sc_pkcs15_cert_info cert_info;
  126|    204|		struct sc_pkcs15_object cert_obj;
  127|    204|		size_t cert_size;
  128|       |
  129|    204|		memset(&cert_info, 0, sizeof(cert_info));
  130|    204|		memset(&cert_obj, 0, sizeof(cert_obj));
  131|       |
  132|    204|		sc_pkcs15_format_id(containers[i].id, &cert_info.id);
  133|    204|		cert_info.authority = containers[i].certdata->authority;
  134|    204|		sc_format_path(containers[i].certdata->path, &cert_info.path);
  135|       |
  136|    204|		r = get_cert_size(card, &cert_info.path, &cert_size);
  137|    204|		if ( r != SC_SUCCESS ) {
  ------------------
  |  |   28|    204|#define SC_SUCCESS				0
  ------------------
  |  Branch (137:8): [True: 123, False: 81]
  ------------------
  138|    123|			sc_log(card->ctx, "Failed to determine size of certificate %s, ignoring container", containers[i].certdata->label);
  ------------------
  |  |   71|    123|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  139|    123|			continue;
  140|    123|		}
  141|       |
  142|     81|		strlcpy(cert_obj.label, containers[i].certdata->label, sizeof(cert_obj.label));
  ------------------
  |  |   43|     81|#define strlcpy _strlcpy
  ------------------
  143|     81|		cert_obj.flags = containers[i].certdata->obj_flags;
  144|       |
  145|     81|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  146|     81|		LOG_TEST_RET(card->ctx, r, "Failed to add certificate");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  147|       |
  148|     81|		if (containers[i].pindata != 0) {
  ------------------
  |  Branch (148:7): [True: 81, False: 0]
  ------------------
  149|     81|			size_t j;
  150|     81|			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|     81|			for (j = 0; j < installed_pin_count; j++) {
  ------------------
  |  Branch (153:16): [True: 7, False: 74]
  ------------------
  154|      7|				if (installed_pins[j] == containers[i].pindata) {
  ------------------
  |  Branch (154:9): [True: 7, False: 0]
  ------------------
  155|      7|					is_pin_installed = 1;
  156|      7|					break;
  157|      7|				}
  158|      7|			}
  159|       |
  160|     81|			if (!is_pin_installed) {
  ------------------
  |  Branch (160:8): [True: 74, False: 7]
  ------------------
  161|     74|				struct sc_pkcs15_auth_info pin_info;
  162|     74|				struct sc_pkcs15_object pin_obj;
  163|       |
  164|     74|				if (installed_pin_count < (int)(sizeof(installed_pins) / sizeof(ppindata))) {
  ------------------
  |  Branch (164:9): [True: 74, False: 0]
  ------------------
  165|     74|					installed_pins[installed_pin_count++] = containers[i].pindata;
  166|     74|				} 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|     74|				memset(&pin_info, 0, sizeof(pin_info));
  172|     74|				memset(&pin_obj, 0, sizeof(pin_obj));
  173|       |
  174|     74|				sc_pkcs15_format_id(containers[i].pindata->id, &pin_info.auth_id);
  175|     74|				pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|     74|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  176|     74|				pin_info.attrs.pin.reference = containers[i].pindata->ref;
  177|     74|				pin_info.attrs.pin.flags = containers[i].pindata->flags;
  178|     74|				pin_info.attrs.pin.type = containers[i].pindata->type;
  179|     74|				pin_info.attrs.pin.min_length = containers[i].pindata->minlen;
  180|     74|				pin_info.attrs.pin.stored_length = containers[i].pindata->storedlen;
  181|     74|				pin_info.attrs.pin.max_length = containers[i].pindata->maxlen;
  182|     74|				pin_info.attrs.pin.pad_char = containers[i].pindata->pad_char;
  183|     74|				if (containers[i].pindata->path != NULL)
  ------------------
  |  Branch (183:9): [True: 74, False: 0]
  ------------------
  184|     74|					sc_format_path(containers[i].pindata->path, &pin_info.path);
  185|     74|				pin_info.tries_left = -1;
  186|     74|				pin_info.max_tries = containers[i].pindata->max_tries;
  187|       |
  188|     74|				strlcpy(pin_obj.label, containers[i].pindata->label, sizeof(pin_obj.label));
  ------------------
  |  |   43|     74|#define strlcpy _strlcpy
  ------------------
  189|     74|				pin_obj.flags = containers[i].pindata->obj_flags;
  190|       |
  191|     74|				r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  192|     74|				LOG_TEST_RET(card->ctx, r, "Failed to add PIN object");
  ------------------
  |  |  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: 0, False: 74]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     74|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 74]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|     74|			}
  194|     81|		}
  195|       |
  196|     81|		if (containers[i].prdata != 0) {
  ------------------
  |  Branch (196:7): [True: 81, False: 0]
  ------------------
  197|     81|			struct sc_pkcs15_prkey_info prkey_info;
  198|     81|			struct sc_pkcs15_object prkey_obj;
  199|     81|			int modulus_len = containers[i].prdata->modulus_len;
  200|     81|			memset(&prkey_info, 0, sizeof(prkey_info));
  201|     81|			memset(&prkey_obj, 0, sizeof(prkey_obj));
  202|       |
  203|     81|			sc_pkcs15_format_id(containers[i].id, &prkey_info.id);
  204|     81|			prkey_info.usage = containers[i].prdata->usage;
  205|     81|			prkey_info.native = 1;
  206|     81|			prkey_info.key_reference = containers[i].prdata->ref;
  207|     81|			prkey_info.modulus_length = modulus_len;
  208|     81|			sc_format_path(containers[i].prdata->path, &prkey_info.path);
  209|       |
  210|     81|			strlcpy(prkey_obj.label, containers[i].prdata->label, sizeof(prkey_obj.label));
  ------------------
  |  |   43|     81|#define strlcpy _strlcpy
  ------------------
  211|     81|			prkey_obj.flags = containers[i].prdata->obj_flags;
  212|     81|			if (containers[i].prdata->auth_id) {
  ------------------
  |  Branch (212:8): [True: 81, False: 0]
  ------------------
  213|     81|				sc_pkcs15_format_id(containers[i].prdata->auth_id, &prkey_obj.auth_id);
  214|     81|			}
  215|       |
  216|     81|			r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  217|     81|			LOG_TEST_RET(card->ctx, r, "Failed to add RSA prkey");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  218|     81|		}
  219|       |
  220|     81|		containers_added++;
  221|     81|	}
  222|       |
  223|    102|	if (containers_added == 0) {
  ------------------
  |  Branch (223:6): [True: 28, False: 74]
  ------------------
  224|     28|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     28|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  225|     74|	} else {
  226|     74|		r = SC_SUCCESS;
  ------------------
  |  |   28|     74|#define SC_SUCCESS				0
  ------------------
  227|     74|	}
  228|       |
  229|    102|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    102|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    102|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    102|	int _ret = r; \
  |  |  |  |  155|    102|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 102, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    102|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 28, False: 74]
  |  |  |  |  ------------------
  |  |  |  |  157|    102|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    102|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    102|	return _ret; \
  |  |  |  |  163|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  230|    102|}
pkcs15-starcos-esign.c:get_cert_size:
  101|    204|{
  102|    204|	int r;
  103|    204|	sc_file_t *file = NULL;
  104|       |
  105|    204|	r = sc_select_file(card, path, &file);
  106|    204|	LOG_TEST_RET(card->ctx, r, "Failed to select EF certificate");
  ------------------
  |  |  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: 123, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  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|    204|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|       |
  108|     81|	*psize = file->size;
  109|     81|	sc_file_free(file);
  110|       |
  111|     81|	return SC_SUCCESS;
  ------------------
  |  |   28|     81|#define SC_SUCCESS				0
  ------------------
  112|    204|}

sc_pkcs15_is_emulation_only:
   89|  13.5k|{
   90|  13.5k|	switch (card->type) {
   91|    785|		case SC_CARD_TYPE_GEMSAFEV1_PTEID:
  ------------------
  |  Branch (91:3): [True: 785, False: 12.7k]
  ------------------
   92|    788|		case SC_CARD_TYPE_OPENPGP_V1:
  ------------------
  |  Branch (92:3): [True: 3, False: 13.5k]
  ------------------
   93|    800|		case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (93:3): [True: 12, False: 13.5k]
  ------------------
   94|    990|		case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (94:3): [True: 190, False: 13.3k]
  ------------------
   95|    993|		case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (95:3): [True: 3, False: 13.5k]
  ------------------
   96|    993|		case SC_CARD_TYPE_SC_HSM:
  ------------------
  |  Branch (96:3): [True: 0, False: 13.5k]
  ------------------
   97|    993|		case SC_CARD_TYPE_SC_HSM_SOC:
  ------------------
  |  Branch (97:3): [True: 0, False: 13.5k]
  ------------------
   98|    993|		case SC_CARD_TYPE_DNIE_BASE:
  ------------------
  |  Branch (98:3): [True: 0, False: 13.5k]
  ------------------
   99|    993|		case SC_CARD_TYPE_DNIE_BLANK:
  ------------------
  |  Branch (99:3): [True: 0, False: 13.5k]
  ------------------
  100|    993|		case SC_CARD_TYPE_DNIE_ADMIN:
  ------------------
  |  Branch (100:3): [True: 0, False: 13.5k]
  ------------------
  101|  1.51k|		case SC_CARD_TYPE_DNIE_USER:
  ------------------
  |  Branch (101:3): [True: 521, False: 12.9k]
  ------------------
  102|  1.51k|		case SC_CARD_TYPE_DNIE_TERMINATED:
  ------------------
  |  Branch (102:3): [True: 0, False: 13.5k]
  ------------------
  103|  1.51k|		case SC_CARD_TYPE_IASECC_GEMALTO:
  ------------------
  |  Branch (103:3): [True: 5, False: 13.5k]
  ------------------
  104|  1.59k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (104:3): [True: 73, False: 13.4k]
  ------------------
  105|  1.59k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (105:3): [True: 1, False: 13.5k]
  ------------------
  106|  1.59k|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (106:3): [True: 0, False: 13.5k]
  ------------------
  107|  1.71k|		case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (107:3): [True: 119, False: 13.3k]
  ------------------
  108|  1.99k|		case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (108:3): [True: 287, False: 13.2k]
  ------------------
  109|  2.15k|		case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (109:3): [True: 158, False: 13.3k]
  ------------------
  110|  2.15k|		case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (110:3): [True: 0, False: 13.5k]
  ------------------
  111|  2.21k|		case SC_CARD_TYPE_ESTEID_2018:
  ------------------
  |  Branch (111:3): [True: 55, False: 13.4k]
  ------------------
  112|  2.36k|		case SC_CARD_TYPE_CARDOS_V5_0:
  ------------------
  |  Branch (112:3): [True: 156, False: 13.3k]
  ------------------
  113|  2.65k|		case SC_CARD_TYPE_CARDOS_V5_3:
  ------------------
  |  Branch (113:3): [True: 287, False: 13.2k]
  ------------------
  114|  2.84k|		case SC_CARD_TYPE_NQ_APPLET:
  ------------------
  |  Branch (114:3): [True: 187, False: 13.3k]
  ------------------
  115|  2.84k|		case SC_CARD_TYPE_NQ_APPLET_RFID:
  ------------------
  |  Branch (115:3): [True: 0, False: 13.5k]
  ------------------
  116|  3.01k|		case SC_CARD_TYPE_STARCOS_V3_4_ESIGN:
  ------------------
  |  Branch (116:3): [True: 177, False: 13.3k]
  ------------------
  117|  3.01k|		case SC_CARD_TYPE_STARCOS_V3_5_ESIGN:
  ------------------
  |  Branch (117:3): [True: 0, False: 13.5k]
  ------------------
  118|  3.03k|		case SC_CARD_TYPE_SKEID_V3:
  ------------------
  |  Branch (118:3): [True: 16, False: 13.5k]
  ------------------
  119|  3.04k|		case SC_CARD_TYPE_EOI:
  ------------------
  |  Branch (119:3): [True: 9, False: 13.5k]
  ------------------
  120|  3.04k|		case SC_CARD_TYPE_EOI_CONTACTLESS:
  ------------------
  |  Branch (120:3): [True: 0, False: 13.5k]
  ------------------
  121|  3.04k|		case SC_CARD_TYPE_DTRUST_V4_1_STD:
  ------------------
  |  Branch (121:3): [True: 0, False: 13.5k]
  ------------------
  122|  3.04k|		case SC_CARD_TYPE_DTRUST_V4_4_STD:
  ------------------
  |  Branch (122:3): [True: 0, False: 13.5k]
  ------------------
  123|  3.04k|		case SC_CARD_TYPE_DTRUST_V4_1_MULTI:
  ------------------
  |  Branch (123:3): [True: 0, False: 13.5k]
  ------------------
  124|  3.04k|		case SC_CARD_TYPE_DTRUST_V4_1_M100:
  ------------------
  |  Branch (124:3): [True: 0, False: 13.5k]
  ------------------
  125|  3.04k|		case SC_CARD_TYPE_DTRUST_V4_4_MULTI:
  ------------------
  |  Branch (125:3): [True: 0, False: 13.5k]
  ------------------
  126|  3.04k|		case SC_CARD_TYPE_DTRUST_V5_1_STD:
  ------------------
  |  Branch (126:3): [True: 0, False: 13.5k]
  ------------------
  127|  3.04k|		case SC_CARD_TYPE_DTRUST_V5_4_STD:
  ------------------
  |  Branch (127:3): [True: 0, False: 13.5k]
  ------------------
  128|  3.04k|		case SC_CARD_TYPE_DTRUST_V5_1_MULTI:
  ------------------
  |  Branch (128:3): [True: 0, False: 13.5k]
  ------------------
  129|  3.04k|		case SC_CARD_TYPE_DTRUST_V5_1_M100:
  ------------------
  |  Branch (129:3): [True: 0, False: 13.5k]
  ------------------
  130|  3.04k|		case SC_CARD_TYPE_DTRUST_V5_4_MULTI:
  ------------------
  |  Branch (130:3): [True: 0, False: 13.5k]
  ------------------
  131|  3.04k|		case SC_CARD_TYPE_LTEID:
  ------------------
  |  Branch (131:3): [True: 0, False: 13.5k]
  ------------------
  132|  3.04k|			return 1;
  133|  10.4k|		default:
  ------------------
  |  Branch (133:3): [True: 10.4k, False: 3.04k]
  ------------------
  134|  10.4k|			return 0;
  135|  13.5k|	}
  136|  13.5k|}
sc_pkcs15_bind_synthetic:
  140|  13.2k|{
  141|  13.2k|	sc_context_t		*ctx = p15card->card->ctx;
  142|  13.2k|	scconf_block		*conf_block, **blocks, *blk;
  143|  13.2k|	int			i, r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  13.2k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  144|       |
  145|  13.2k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  13.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  13.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  13.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 13.2k]
  |  |  ------------------
  ------------------
  146|  13.2k|	conf_block = NULL;
  147|       |
  148|  13.2k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
  149|       |
  150|  13.2k|	if (!conf_block) {
  ------------------
  |  Branch (150:6): [True: 13.2k, False: 0]
  ------------------
  151|       |		/* no conf file found => try builtin drivers  */
  152|  13.2k|		sc_log(ctx, "no conf file (or section), trying all builtin emulators");
  ------------------
  |  |   71|  13.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  153|   282k|		for (i = 0; builtin_emulators[i].name; i++) {
  ------------------
  |  Branch (153:15): [True: 274k, False: 7.49k]
  ------------------
  154|   274k|			sc_log(ctx, "trying %s", builtin_emulators[i].name);
  ------------------
  |  |   71|   274k|#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|   274k|			r = builtin_emulators[i].handler(p15card, aid);
  156|   274k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|   274k|#define SC_SUCCESS				0
  ------------------
  |  Branch (156:8): [True: 5.79k, False: 268k]
  ------------------
  157|       |				/* we got a hit */
  158|  5.79k|				goto out;
  159|   274k|		}
  160|  13.2k|	} 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|  13.2k|out:
  222|  13.2k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  13.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:6): [True: 5.79k, False: 7.49k]
  ------------------
  223|  5.79k|		p15card->magic  = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  5.79k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  224|  5.79k|		p15card->flags |= SC_PKCS15_CARD_FLAG_EMULATED;
  ------------------
  |  |  601|  5.79k|#define SC_PKCS15_CARD_FLAG_EMULATED			0x02000000
  ------------------
  225|  7.49k|	} else {
  226|  7.49k|		if (r != SC_ERROR_WRONG_CARD)
  ------------------
  |  |   94|  7.49k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (226:7): [True: 140, False: 7.35k]
  ------------------
  227|    140|			sc_log(ctx, "Failed to load card emulator: %s", sc_strerror(r));
  ------------------
  |  |   71|    140|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  228|  7.49k|	}
  229|       |
  230|  13.2k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  13.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  13.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  13.2k|	int _ret = r; \
  |  |  |  |  155|  13.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  13.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  7.49k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.49k, False: 5.79k]
  |  |  |  |  ------------------
  |  |  |  |  157|  13.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  13.2k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  13.2k|	return _ret; \
  |  |  |  |  163|  13.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  231|  13.2k|}
sc_pkcs15emu_add_pin_obj:
  367|  7.43k|{
  368|  7.43k|	sc_pkcs15_auth_info_t pin = *in_pin;
  369|       |
  370|  7.43k|	pin.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|  7.43k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  371|  7.43k|	if(!pin.auth_method) /* or SC_AC_NONE */
  ------------------
  |  Branch (371:5): [True: 6.90k, False: 529]
  ------------------
  372|  6.90k|		pin.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|  6.90k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  373|       |
  374|  7.43k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_AUTH_PIN, obj, &pin);
  ------------------
  |  |  445|  7.43k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  375|  7.43k|}
sc_pkcs15emu_add_rsa_prkey:
  379|  2.94k|{
  380|  2.94k|	sc_pkcs15_prkey_info_t key = *in_key;
  381|       |
  382|  2.94k|	if (key.access_flags == 0)
  ------------------
  |  Branch (382:6): [True: 2.94k, False: 0]
  ------------------
  383|  2.94k|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|  2.94k|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  384|  2.94k|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|  2.94k|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  385|  2.94k|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|  2.94k|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  386|  2.94k|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|  2.94k|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  387|       |
  388|  2.94k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_RSA, obj, &key);
  ------------------
  |  |  419|  2.94k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  389|  2.94k|}
sc_pkcs15emu_add_rsa_pubkey:
  393|    849|{
  394|    849|	sc_pkcs15_pubkey_info_t key = *in_key;
  395|       |
  396|    849|	if (key.access_flags == 0)
  ------------------
  |  Branch (396:6): [True: 849, False: 0]
  ------------------
  397|    849|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|    849|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  398|       |
  399|    849|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_RSA, obj, &key);
  ------------------
  |  |  426|    849|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  400|    849|}
sc_pkcs15emu_add_ec_prkey:
  404|    889|{
  405|    889|	sc_pkcs15_prkey_info_t key = *in_key;
  406|       |
  407|    889|	if (key.access_flags == 0)
  ------------------
  |  Branch (407:6): [True: 889, False: 0]
  ------------------
  408|    889|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|    889|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  409|    889|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|    889|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  410|    889|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|    889|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  411|    889|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|    889|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  412|       |
  413|    889|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_EC, obj, &key);
  ------------------
  |  |  421|    889|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  414|    889|}
sc_pkcs15emu_add_ec_pubkey:
  418|    892|{
  419|    892|	sc_pkcs15_pubkey_info_t key = *in_key;
  420|       |
  421|    892|	if (key.access_flags == 0)
  ------------------
  |  Branch (421:6): [True: 892, False: 0]
  ------------------
  422|    892|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|    892|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  423|       |
  424|    892|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_EC, obj, &key);
  ------------------
  |  |  428|    892|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  425|    892|}
sc_pkcs15emu_add_x509_cert:
  479|  3.14k|{
  480|  3.14k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_CERT_X509, obj, cert);
  ------------------
  |  |  439|  3.14k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  481|  3.14k|}
sc_pkcs15emu_add_data_object:
  485|  2.02k|{
  486|  2.02k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT, obj, data);
  ------------------
  |  |  442|  2.02k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  487|  2.02k|}
sc_pkcs15emu_object_add:
  491|  41.6k|{
  492|  41.6k|	sc_pkcs15_object_t *obj;
  493|  41.6k|	unsigned int	df_type;
  494|  41.6k|	size_t		data_len;
  495|       |
  496|  41.6k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  41.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  41.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  41.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 41.6k]
  |  |  ------------------
  ------------------
  497|       |
  498|  41.6k|	obj = calloc(1, sizeof(*obj));
  499|  41.6k|	if (!obj) {
  ------------------
  |  Branch (499:6): [True: 0, False: 41.6k]
  ------------------
  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|  41.6k|	memcpy(obj, in_obj, sizeof(*obj));
  504|  41.6k|	obj->type = type;
  505|       |
  506|  41.6k|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  41.6k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  507|  7.43k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  7.43k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (507:2): [True: 7.43k, False: 34.2k]
  ------------------
  508|  7.43k|		df_type  = SC_PKCS15_AODF;
  ------------------
  |  |  496|  7.43k|#define SC_PKCS15_AODF			8
  ------------------
  509|  7.43k|		data_len = sizeof(struct sc_pkcs15_auth_info);
  510|  7.43k|		break;
  511|  4.83k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  4.83k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (511:2): [True: 4.83k, False: 36.8k]
  ------------------
  512|  4.83k|		df_type  = SC_PKCS15_PRKDF;
  ------------------
  |  |  488|  4.83k|#define SC_PKCS15_PRKDF			0
  ------------------
  513|  4.83k|		data_len = sizeof(struct sc_pkcs15_prkey_info);
  514|  4.83k|		break;
  515|  1.97k|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|  1.97k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (515:2): [True: 1.97k, False: 39.6k]
  ------------------
  516|  1.97k|		df_type = SC_PKCS15_PUKDF;
  ------------------
  |  |  489|  1.97k|#define SC_PKCS15_PUKDF			1
  ------------------
  517|  1.97k|		data_len = sizeof(struct sc_pkcs15_pubkey_info);
  518|  1.97k|		break;
  519|  3.47k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  3.47k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (519:2): [True: 3.47k, False: 38.1k]
  ------------------
  520|  3.47k|		df_type = SC_PKCS15_CDF;
  ------------------
  |  |  492|  3.47k|#define SC_PKCS15_CDF			4
  ------------------
  521|  3.47k|		data_len = sizeof(struct sc_pkcs15_cert_info);
  522|  3.47k|		break;
  523|  23.9k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  23.9k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (523:2): [True: 23.9k, False: 17.7k]
  ------------------
  524|  23.9k|		df_type = SC_PKCS15_DODF;
  ------------------
  |  |  495|  23.9k|#define SC_PKCS15_DODF			7
  ------------------
  525|  23.9k|		data_len = sizeof(struct sc_pkcs15_data_info);
  526|  23.9k|		break;
  527|      0|	default:
  ------------------
  |  Branch (527:2): [True: 0, False: 41.6k]
  ------------------
  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|  41.6k|	}
  532|       |
  533|  41.6k|	obj->data = calloc(1, data_len);
  534|  41.6k|	if (obj->data == NULL) {
  ------------------
  |  Branch (534:6): [True: 0, False: 41.6k]
  ------------------
  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|  41.6k|	memcpy(obj->data, data, data_len);
  539|       |
  540|  41.6k|	obj->df = sc_pkcs15emu_get_df(p15card, df_type);
  541|  41.6k|	sc_pkcs15_add_object(p15card, obj);
  542|       |
  543|  41.6k|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  41.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  41.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  41.6k|	int _ret = r; \
  |  |  |  |  155|  41.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 41.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  41.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 41.6k]
  |  |  |  |  ------------------
  |  |  |  |  157|  41.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  41.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|  41.6k|	return _ret; \
  |  |  |  |  163|  41.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  544|  41.6k|}
pkcs15-syn.c:sc_pkcs15emu_get_df:
  338|  41.6k|{
  339|  41.6k|	sc_pkcs15_df_t	*df;
  340|  41.6k|	sc_file_t	*file;
  341|  41.6k|	int		created = 0;
  342|       |
  343|  52.9k|	while (1) {
  ------------------
  |  Branch (343:9): [True: 52.9k, Folded]
  ------------------
  344|  98.8k|		for (df = p15card->df_list; df; df = df->next) {
  ------------------
  |  Branch (344:31): [True: 87.5k, False: 11.3k]
  ------------------
  345|  87.5k|			if (df->type == type) {
  ------------------
  |  Branch (345:8): [True: 41.6k, False: 45.8k]
  ------------------
  346|  41.6k|				if (created)
  ------------------
  |  Branch (346:9): [True: 11.3k, False: 30.3k]
  ------------------
  347|  11.3k|					df->enumerated = 1;
  348|  41.6k|				return df;
  349|  41.6k|			}
  350|  87.5k|		}
  351|       |
  352|  11.3k|		if (created != 0)
  ------------------
  |  Branch (352:7): [True: 0, False: 11.3k]
  ------------------
  353|      0|			return NULL;
  354|       |
  355|  11.3k|		file = sc_file_new();
  356|  11.3k|		if (!file)
  ------------------
  |  Branch (356:7): [True: 0, False: 11.3k]
  ------------------
  357|      0|			return NULL;
  358|  11.3k|		sc_format_path("11001101", &file->path);
  359|  11.3k|		sc_pkcs15_add_df(p15card, type, &file->path);
  360|  11.3k|		sc_file_free(file);
  361|  11.3k|		created++;
  362|  11.3k|	}
  363|  41.6k|}

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

sc_pkcs15_parse_tokeninfo:
  145|    849|{
  146|    849|	int r;
  147|    849|	size_t ii;
  148|    849|	u8 serial[128];
  149|    849|	size_t serial_len = sizeof(serial);
  150|    849|	u8 mnfid[SC_PKCS15_MAX_LABEL_SIZE];
  151|    849|	size_t mnfid_len  = sizeof(mnfid) - 1;
  152|    849|	u8 label[SC_PKCS15_MAX_LABEL_SIZE];
  153|    849|	size_t label_len = sizeof(label) - 1;
  154|    849|	u8 last_update[32], profile_indication[SC_PKCS15_MAX_LABEL_SIZE];
  155|    849|	size_t lupdate_len = sizeof(last_update) - 1, pi_len = sizeof(profile_indication) - 1;
  156|    849|	size_t flags_len   = sizeof(ti->flags);
  157|    849|	u8 preferred_language[3];
  158|    849|	size_t lang_length = sizeof(preferred_language);
  159|    849|	struct sc_asn1_entry asn1_supported_algorithms[SC_MAX_SUPPORTED_ALGORITHMS + 1],
  160|    849|			asn1_algo_infos[SC_MAX_SUPPORTED_ALGORITHMS][7],
  161|    849|			asn1_algo_infos_parameters[SC_MAX_SUPPORTED_ALGORITHMS][3];
  162|    849|	size_t reference_len = sizeof(ti->supported_algos[0].reference);
  163|    849|	size_t mechanism_len = sizeof(ti->supported_algos[0].mechanism);
  164|    849|	size_t parameter_len = sizeof(ti->supported_algos[0].parameters);
  165|    849|	size_t operations_len = sizeof(ti->supported_algos[0].operations);
  166|    849|	size_t algo_ref_len = sizeof(ti->supported_algos[0].algo_ref);
  167|       |
  168|    849|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  169|    849|	struct sc_asn1_entry asn1_profile_indication[C_ASN1_PROFILE_INDICATION_SIZE];
  170|    849|	struct sc_asn1_entry asn1_toki_attrs[C_ASN1_TOKI_ATTRS_SIZE], asn1_tokeninfo[3], asn1_twlabel[3];
  171|       |
  172|    849|	memset(last_update, 0, sizeof(last_update));
  173|    849|	memset(label, 0, sizeof(label));
  174|    849|	memset(profile_indication, 0, sizeof(profile_indication));
  175|    849|	memset(mnfid, 0, sizeof(mnfid));
  176|       |
  177|    849|	sc_copy_asn1_entry(c_asn1_twlabel, asn1_twlabel);
  178|    849|	sc_copy_asn1_entry(c_asn1_toki_attrs, asn1_toki_attrs);
  179|    849|	sc_copy_asn1_entry(c_asn1_tokeninfo, asn1_tokeninfo);
  180|    849|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  181|    849|	sc_format_asn1_entry(asn1_twlabel, label, &label_len, 0);
  182|    849|	sc_copy_asn1_entry(c_asn1_profile_indication, asn1_profile_indication);
  183|       |
  184|  14.4k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++) {
  ------------------
  |  |   61|  14.4k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (184:13): [True: 13.5k, False: 849]
  ------------------
  185|  13.5k|		sc_copy_asn1_entry(c_asn1_algorithm_info, asn1_algo_infos[ii]);
  186|  13.5k|		sc_copy_asn1_entry(c_asn1_algorithm_info_parameters,
  187|  13.5k|			asn1_algo_infos_parameters[ii]);
  188|  13.5k|	}
  189|    849|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  190|       |
  191|  14.4k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++)   {
  ------------------
  |  |   61|  14.4k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (191:13): [True: 13.5k, False: 849]
  ------------------
  192|  13.5k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 0, &ti->supported_algos[ii].reference, &reference_len, 0);
  193|  13.5k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 1, &ti->supported_algos[ii].mechanism, &mechanism_len, 0);
  194|  13.5k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 2,
  195|  13.5k|			asn1_algo_infos_parameters[ii], NULL, 0);
  196|  13.5k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 0,
  197|  13.5k|			NULL, NULL, 0);
  198|  13.5k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 1,
  199|  13.5k|			&ti->supported_algos[ii].parameters, &parameter_len, 0);
  200|  13.5k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 3, &ti->supported_algos[ii].operations, &operations_len, 0);
  201|  13.5k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 4, &ti->supported_algos[ii].algo_id, NULL, 1);
  202|  13.5k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 5, &ti->supported_algos[ii].algo_ref, &algo_ref_len, 0);
  203|  13.5k|		sc_format_asn1_entry(asn1_supported_algorithms + ii, asn1_algo_infos[ii], NULL, 0);
  204|  13.5k|	}
  205|       |
  206|    849|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  207|    849|	sc_format_asn1_entry(asn1_last_update + 1, &ti->last_update.path, NULL, 0);
  208|       |
  209|    849|	sc_format_asn1_entry(asn1_profile_indication + 0, &ti->profile_indication.oid, NULL, 0);
  210|    849|	sc_format_asn1_entry(asn1_profile_indication + 1, profile_indication, &pi_len, 0);
  211|       |
  212|    849|	sc_format_asn1_entry(asn1_toki_attrs + 0, &ti->version, NULL, 0);
  213|    849|	sc_format_asn1_entry(asn1_toki_attrs + 1, serial, &serial_len, 0);
  214|    849|	sc_format_asn1_entry(asn1_toki_attrs + 2, mnfid, &mnfid_len, 0);
  215|    849|	sc_format_asn1_entry(asn1_toki_attrs + 3, label, &label_len, 0);
  216|    849|	sc_format_asn1_entry(asn1_toki_attrs + 4, asn1_twlabel, NULL, 0);
  217|    849|	sc_format_asn1_entry(asn1_toki_attrs + 5, &ti->flags, &flags_len, 0);
  218|    849|	sc_format_asn1_entry(asn1_toki_attrs + 6, &ti->seInfo, &ti->num_seInfo, 0);
  219|    849|	sc_format_asn1_entry(asn1_toki_attrs + 7, NULL, NULL, 0);
  220|    849|	sc_format_asn1_entry(asn1_toki_attrs + 8, asn1_supported_algorithms, NULL, 0);
  221|    849|	sc_format_asn1_entry(asn1_toki_attrs + 9, NULL, NULL, 0);
  222|    849|	sc_format_asn1_entry(asn1_toki_attrs + 10, NULL, NULL, 0);
  223|    849|	sc_format_asn1_entry(asn1_toki_attrs + 11, asn1_last_update, NULL, 0);
  224|    849|	sc_format_asn1_entry(asn1_toki_attrs + 12, preferred_language, &lang_length, 0);
  225|    849|	sc_format_asn1_entry(asn1_toki_attrs + 13, asn1_profile_indication, NULL, 0);
  226|    849|	sc_format_asn1_entry(asn1_tokeninfo, asn1_toki_attrs, NULL, 0);
  227|       |
  228|    849|	r = sc_asn1_decode(ctx, asn1_tokeninfo, buf, blen, NULL, NULL);
  229|    849|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    849|#define SC_SUCCESS				0
  ------------------
  |  Branch (229:6): [True: 417, False: 432]
  ------------------
  230|       |		/* The decoding could have allocated something we need to free */
  231|    417|		sc_pkcs15_clear_tokeninfo(ti);
  232|    417|		LOG_TEST_RET(ctx, r, "ASN.1 parsing of EF(TokenInfo) failed");
  ------------------
  |  |  174|    417|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    417|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    417|	int _ret = (r); \
  |  |  |  |  168|    417|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 417, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    417|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    417|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    417|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    417|		return _ret; \
  |  |  |  |  172|    417|	} \
  |  |  |  |  173|    417|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|    417|	}
  234|       |
  235|    432|	if (asn1_toki_attrs[1].flags & SC_ASN1_PRESENT && serial_len > 0)   {
  ------------------
  |  |  147|    864|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (235:6): [True: 321, False: 111]
  |  Branch (235:52): [True: 313, False: 8]
  ------------------
  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|    432|	if (ti->manufacturer_id == NULL) {
  ------------------
  |  Branch (244:6): [True: 432, False: 0]
  ------------------
  245|    432|		if (asn1_toki_attrs[2].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    432|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (245:7): [True: 32, False: 400]
  ------------------
  246|     32|			ti->manufacturer_id = strdup((char *) mnfid);
  247|    400|		else
  248|    400|			ti->manufacturer_id = strdup("(unknown)");
  249|    432|		if (ti->manufacturer_id == NULL)
  ------------------
  |  Branch (249:7): [True: 0, False: 432]
  ------------------
  250|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  251|    432|	}
  252|    432|	if (ti->label == NULL) {
  ------------------
  |  Branch (252:6): [True: 432, False: 0]
  ------------------
  253|    432|		if (asn1_toki_attrs[3].flags & SC_ASN1_PRESENT ||
  ------------------
  |  |  147|    864|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (253:7): [True: 18, False: 414]
  ------------------
  254|    414|		    asn1_toki_attrs[4].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    414|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (254:7): [True: 0, False: 414]
  ------------------
  255|     18|			ti->label = strdup((char *) label);
  256|    414|		else
  257|    414|			ti->label = strdup("(unknown)");
  258|    432|		if (ti->label == NULL)
  ------------------
  |  Branch (258:7): [True: 0, False: 432]
  ------------------
  259|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  260|    432|	}
  261|    432|	if (asn1_toki_attrs[11].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    432|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (261:6): [True: 104, False: 328]
  ------------------
  262|    104|		if (asn1_last_update[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    104|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (262:7): [True: 11, False: 93]
  ------------------
  263|     11|			sc_log(ctx, "LastUpdate.generalizedTime present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  264|     11|			ti->last_update.gtime = strdup((char *)last_update);
  265|     11|			if (ti->last_update.gtime == NULL)
  ------------------
  |  Branch (265:8): [True: 0, False: 11]
  ------------------
  266|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  267|     11|		}
  268|     93|		else if (asn1_last_update[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|     93|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (268:12): [True: 72, False: 21]
  ------------------
  269|     72|			sc_log(ctx, "LastUpdate.referencedTime present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  270|     72|		}
  271|    104|	}
  272|    432|	if (asn1_toki_attrs[12].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    432|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (272:6): [True: 5, False: 427]
  ------------------
  273|      5|		preferred_language[2] = 0;
  274|      5|		ti->preferred_language = strdup((char *)preferred_language);
  275|      5|		if (ti->preferred_language == NULL)
  ------------------
  |  Branch (275:7): [True: 0, False: 5]
  ------------------
  276|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  277|      5|	}
  278|       |
  279|    432|	sc_init_oid(&ti->profile_indication.oid);
  280|    432|	if (asn1_toki_attrs[13].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    432|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (280:6): [True: 187, False: 245]
  ------------------
  281|    187|		if (asn1_profile_indication[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    187|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (281:7): [True: 3, False: 184]
  ------------------
  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|    184|		else if (asn1_profile_indication[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|    184|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (284:12): [True: 180, False: 4]
  ------------------
  285|    180|			sc_log(ctx, "ProfileIndication.name present");
  ------------------
  |  |   71|    180|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  286|    180|			ti->profile_indication.name = strdup((char *)profile_indication);
  287|    180|			if (ti->profile_indication.name == NULL)
  ------------------
  |  Branch (287:8): [True: 0, False: 180]
  ------------------
  288|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  289|    180|		}
  290|    187|	}
  291|       |
  292|    432|	sc_log(ctx, "LastUpdate.path '%s'", sc_print_path(&ti->last_update.path));
  ------------------
  |  |   71|    432|#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|    432|	sc_log(ctx, "ProfileIndication.name '%s'",  ti->profile_indication.name);
  ------------------
  |  |   71|    432|#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|    432|	return SC_SUCCESS;
  ------------------
  |  |   28|    432|#define SC_SUCCESS				0
  ------------------
  295|    432|}
sc_pkcs15_get_lastupdate:
  535|  3.53k|{
  536|  3.53k|	struct sc_context *ctx  = p15card->card->ctx;
  537|  3.53k|	struct sc_file *file = NULL;
  538|  3.53k|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  539|  3.53k|	unsigned char *content, last_update[32] = {0};
  540|  3.53k|	size_t lupdate_len = sizeof(last_update) - 1;
  541|  3.53k|	int r, content_len;
  542|  3.53k|	size_t size;
  543|       |
  544|  3.53k|	if (p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (544:6): [True: 39, False: 3.49k]
  ------------------
  545|     39|		goto done;
  546|       |
  547|  3.49k|	if (!p15card->tokeninfo->last_update.path.len)
  ------------------
  |  Branch (547:6): [True: 2.87k, False: 620]
  ------------------
  548|  2.87k|		return NULL;
  549|       |
  550|    620|	r = sc_select_file(p15card->card, &p15card->tokeninfo->last_update.path, &file);
  551|    620|	if (r < 0)
  ------------------
  |  Branch (551:6): [True: 555, False: 65]
  ------------------
  552|    555|		return NULL;
  553|       |
  554|     65|	size = file->size ? file->size : 1024;
  ------------------
  |  Branch (554:9): [True: 45, False: 20]
  ------------------
  555|     65|	sc_file_free(file);
  556|       |
  557|     65|	content = calloc(1, size);
  558|     65|	if (!content)
  ------------------
  |  Branch (558:6): [True: 0, False: 65]
  ------------------
  559|      0|		return NULL;
  560|       |
  561|     65|	r = sc_read_binary(p15card->card, 0, content, size, 0);
  562|     65|	if (r < 0) {
  ------------------
  |  Branch (562:6): [True: 39, False: 26]
  ------------------
  563|     39|		free(content);
  564|     39|		return NULL;
  565|     39|	}
  566|     26|	content_len = r;
  567|       |
  568|     26|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  569|     26|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  570|       |
  571|     26|	r = sc_asn1_decode(ctx, asn1_last_update, content, content_len, NULL, NULL);
  572|     26|	free(content);
  573|     26|	if (r < 0)
  ------------------
  |  Branch (573:6): [True: 9, False: 17]
  ------------------
  574|      9|		return NULL;
  575|       |
  576|     17|	if (asn1_last_update[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     17|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (576:6): [True: 2, False: 15]
  ------------------
  577|      2|		p15card->tokeninfo->last_update.gtime = strdup((char *)last_update);
  578|      2|		if (!p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (578:7): [True: 0, False: 2]
  ------------------
  579|      0|			return NULL;
  580|      2|	}
  581|     56|done:
  582|     56|	sc_log(ctx, "lastUpdate.gtime '%s'", p15card->tokeninfo->last_update.gtime);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  583|     56|	return p15card->tokeninfo->last_update.gtime;
  584|     17|}
sc_pkcs15_card_new:
  713|  13.5k|{
  714|  13.5k|	struct sc_pkcs15_card *p15card;
  715|       |
  716|  13.5k|	p15card = calloc(1, sizeof(struct sc_pkcs15_card));
  717|  13.5k|	if (p15card == NULL)
  ------------------
  |  Branch (717:6): [True: 0, False: 13.5k]
  ------------------
  718|      0|		return NULL;
  719|       |
  720|  13.5k|	p15card->tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  721|  13.5k|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (721:6): [True: 0, False: 13.5k]
  ------------------
  722|      0|		free(p15card);
  723|      0|		return NULL;
  724|      0|	}
  725|       |
  726|  13.5k|	p15card->magic = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  13.5k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  727|  13.5k|	return p15card;
  728|  13.5k|}
sc_pkcs15_tokeninfo_new:
  733|  9.60k|{
  734|  9.60k|	struct sc_pkcs15_tokeninfo *tokeninfo;
  735|       |
  736|  9.60k|	tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  737|  9.60k|	if (tokeninfo == NULL) {
  ------------------
  |  Branch (737:6): [True: 0, False: 9.60k]
  ------------------
  738|      0|		return NULL;
  739|      0|	}
  740|       |
  741|  9.60k|	sc_init_oid(&tokeninfo->profile_indication.oid);
  742|       |
  743|  9.60k|	return tokeninfo;
  744|  9.60k|}
sc_pkcs15_free_tokeninfo:
  775|  24.5k|{
  776|  24.5k|	if (!tokeninfo)
  ------------------
  |  Branch (776:6): [True: 1.46k, False: 23.1k]
  ------------------
  777|  1.46k|		return;
  778|       |
  779|  23.1k|	sc_pkcs15_clear_tokeninfo(tokeninfo);
  780|  23.1k|	free(tokeninfo);
  781|  23.1k|}
sc_pkcs15_free_app:
  785|  43.4k|{
  786|  43.4k|	if (p15card && p15card->app) {
  ------------------
  |  Branch (786:6): [True: 43.4k, False: 0]
  |  Branch (786:17): [True: 796, False: 42.6k]
  ------------------
  787|    796|		free(p15card->app->label);
  788|    796|		free(p15card->app->ddo.value);
  789|    796|		free(p15card->app);
  790|       |		p15card->app = NULL;
  791|    796|	}
  792|  43.4k|}
sc_pkcs15_card_free:
  797|  13.5k|{
  798|  13.5k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC)
  ------------------
  |  |  519|  13.5k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (798:6): [True: 0, False: 13.5k]
  |  Branch (798:25): [True: 0, False: 13.5k]
  ------------------
  799|      0|		return;
  800|       |
  801|  13.5k|	if (p15card->ops.clear)
  ------------------
  |  Branch (801:6): [True: 839, False: 12.6k]
  ------------------
  802|    839|		p15card->ops.clear(p15card);
  803|       |
  804|       |	/* For more complicated MD data a dedicated release procedure
  805|       |	 * has to be implemented. */
  806|  13.5k|	if (p15card->md_data)
  ------------------
  |  Branch (806:6): [True: 0, False: 13.5k]
  ------------------
  807|      0|		free(p15card->md_data);
  808|       |
  809|  13.5k|	sc_pkcs15_free_app(p15card);
  810|  13.5k|	sc_pkcs15_remove_objects(p15card);
  811|  13.5k|	sc_pkcs15_remove_dfs(p15card);
  812|  13.5k|	sc_pkcs15_free_unusedspace(p15card);
  813|  13.5k|	p15card->unusedspace_read = 0;
  814|       |
  815|  13.5k|	sc_file_free(p15card->file_app);
  816|  13.5k|	sc_file_free(p15card->file_tokeninfo);
  817|  13.5k|	sc_file_free(p15card->file_odf);
  818|  13.5k|	sc_file_free(p15card->file_unusedspace);
  819|       |
  820|  13.5k|	p15card->magic = 0;
  821|  13.5k|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  822|  13.5k|	sc_pkcs15_free_app(p15card);
  823|  13.5k|	free(p15card);
  824|  13.5k|}
sc_pkcs15_card_clear:
  829|  15.8k|{
  830|  15.8k|	if (p15card == NULL)
  ------------------
  |  Branch (830:6): [True: 0, False: 15.8k]
  ------------------
  831|      0|		return;
  832|       |
  833|  15.8k|	if (p15card->ops.clear)
  ------------------
  |  Branch (833:6): [True: 703, False: 15.1k]
  ------------------
  834|    703|		p15card->ops.clear(p15card);
  835|       |
  836|  15.8k|	p15card->flags = 0;
  837|  15.8k|	p15card->tokeninfo->version = 0;
  838|  15.8k|	p15card->tokeninfo->flags   = 0;
  839|       |
  840|  15.8k|	sc_pkcs15_remove_objects(p15card);
  841|  15.8k|	sc_pkcs15_remove_dfs(p15card);
  842|       |
  843|  15.8k|	p15card->df_list = NULL;
  844|  15.8k|	sc_file_free(p15card->file_app);
  845|  15.8k|	p15card->file_app = NULL;
  846|  15.8k|	sc_file_free(p15card->file_tokeninfo);
  847|  15.8k|	p15card->file_tokeninfo = NULL;
  848|  15.8k|	sc_file_free(p15card->file_odf);
  849|  15.8k|	p15card->file_odf = NULL;
  850|  15.8k|	sc_file_free(p15card->file_unusedspace);
  851|  15.8k|	p15card->file_unusedspace = NULL;
  852|       |
  853|  15.8k|	free(p15card->tokeninfo->label);
  854|  15.8k|	p15card->tokeninfo->label = NULL;
  855|  15.8k|	free(p15card->tokeninfo->serial_number);
  856|  15.8k|	p15card->tokeninfo->serial_number = NULL;
  857|  15.8k|	free(p15card->tokeninfo->manufacturer_id);
  858|  15.8k|	p15card->tokeninfo->manufacturer_id = NULL;
  859|  15.8k|	free(p15card->tokeninfo->last_update.gtime);
  860|  15.8k|	p15card->tokeninfo->last_update.gtime = NULL;
  861|  15.8k|	free(p15card->tokeninfo->preferred_language);
  862|  15.8k|	p15card->tokeninfo->preferred_language = NULL;
  863|  15.8k|	free(p15card->tokeninfo->profile_indication.name);
  864|  15.8k|	p15card->tokeninfo->profile_indication.name = NULL;
  865|  15.8k|	if (p15card->tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (865:6): [True: 18, False: 15.8k]
  ------------------
  866|     18|		size_t i;
  867|     18|		for (i = 0; i < p15card->tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (867:15): [True: 0, False: 18]
  ------------------
  868|      0|			free(p15card->tokeninfo->seInfo[i]);
  869|     18|		free(p15card->tokeninfo->seInfo);
  870|     18|		p15card->tokeninfo->seInfo     = NULL;
  871|     18|		p15card->tokeninfo->num_seInfo = 0;
  872|     18|	}
  873|       |
  874|  15.8k|	sc_pkcs15_free_app(p15card);
  875|  15.8k|}
sc_find_app:
  880|  12.9k|{
  881|  12.9k|	int ii;
  882|       |
  883|  12.9k|	if (card->app_count <= 0)
  ------------------
  |  Branch (883:6): [True: 12.4k, False: 515]
  ------------------
  884|  12.4k|		return NULL;
  885|       |
  886|    515|	if (!aid || !aid->len)
  ------------------
  |  Branch (886:6): [True: 515, False: 0]
  |  Branch (886:14): [True: 0, False: 0]
  ------------------
  887|    515|		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.9k|{
  979|  12.9k|	struct sc_path tmppath;
  980|  12.9k|	struct sc_card    *card = p15card->card;
  981|  12.9k|	struct sc_context *ctx  = card->ctx;
  982|  12.9k|	struct sc_pkcs15_tokeninfo tokeninfo;
  983|  12.9k|	struct sc_pkcs15_df *df;
  984|  12.9k|	const struct sc_app_info *info = NULL;
  985|  12.9k|	unsigned char *buf = NULL;
  986|  12.9k|	size_t len;
  987|  12.9k|	int    err, ok = 0;
  988|       |
  989|  12.9k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  990|       |	/* Enumerate apps now */
  991|  12.9k|	if (card->app_count < 0) {
  ------------------
  |  Branch (991:6): [True: 11.9k, False: 1.01k]
  ------------------
  992|  11.9k|		err = sc_enum_apps(card);
  993|  11.9k|		if (err != SC_SUCCESS)
  ------------------
  |  |   28|  11.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (993:7): [True: 11.6k, False: 350]
  ------------------
  994|  11.6k|			sc_log(ctx, "unable to enumerate apps: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  995|  11.9k|	}
  996|  12.9k|	sc_file_free(p15card->file_app);
  997|  12.9k|	p15card->file_app = sc_file_new();
  998|  12.9k|	if (p15card->file_app == NULL) {
  ------------------
  |  Branch (998:6): [True: 0, False: 12.9k]
  ------------------
  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.9k|	sc_format_path("3F005015", &p15card->file_app->path);
 1004|       |
 1005|  12.9k|	info = sc_find_app(card, aid);
 1006|  12.9k|	if (info)   {
  ------------------
  |  Branch (1006:6): [True: 515, False: 12.4k]
  ------------------
 1007|    515|		sc_log(ctx, "bind to application('%s',aid:'%s')", info->label, sc_dump_hex(info->aid.value, info->aid.len));
  ------------------
  |  |   71|    515|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1008|    515|		sc_pkcs15_free_app(p15card);
 1009|    515|		p15card->app = sc_dup_app_info(info);
 1010|    515|		if (!p15card->app)   {
  ------------------
  |  Branch (1010:7): [True: 0, False: 515]
  ------------------
 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|    515|		if (info->path.len)
  ------------------
  |  Branch (1015:7): [True: 474, False: 41]
  ------------------
 1016|    474|			p15card->file_app->path = info->path;
 1017|       |
 1018|    515|		if (info->ddo.value && info->ddo.len)
  ------------------
  |  Branch (1018:7): [True: 50, False: 465]
  |  Branch (1018:26): [True: 46, False: 4]
  ------------------
 1019|     46|			parse_ddo(p15card, info->ddo.value, info->ddo.len);
 1020|       |
 1021|    515|	}
 1022|  12.4k|	else if (aid)   {
  ------------------
  |  Branch (1022:11): [True: 0, False: 12.4k]
  ------------------
 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.9k|	sc_log(ctx, "application path '%s'", sc_print_path(&p15card->file_app->path));
  ------------------
  |  |   71|  12.9k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1028|       |
 1029|       |	/* Check if pkcs15 directory exists */
 1030|  12.9k|	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.9k|	if ((err != SC_SUCCESS) && (card->app_count < 1)) {
  ------------------
  |  |   28|  12.9k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1035:6): [True: 11.0k, False: 1.96k]
  |  Branch (1035:29): [True: 10.6k, False: 395]
  ------------------
 1036|  10.6k|		sc_format_path("3F00", &p15card->file_app->path);
 1037|  10.6k|		err = SC_SUCCESS;
  ------------------
  |  |   28|  10.6k|#define SC_SUCCESS				0
  ------------------
 1038|  10.6k|	}
 1039|       |
 1040|  12.9k|	if (err < 0)   {
  ------------------
  |  Branch (1040:6): [True: 395, False: 12.5k]
  ------------------
 1041|    395|		sc_log (ctx, "Cannot select application path");
  ------------------
  |  |   71|    395|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1042|    395|		goto end;
 1043|    395|	}
 1044|       |
 1045|  12.5k|	if (p15card->file_odf == NULL) {
  ------------------
  |  Branch (1045:6): [True: 12.5k, False: 9]
  ------------------
 1046|       |		/* check if an ODF is present; we don't know yet whether we have a pkcs15 card */
 1047|  12.5k|		sc_format_path("5031", &tmppath);
 1048|  12.5k|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
 1049|  12.5k|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|  12.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1049:7): [True: 3, False: 12.5k]
  ------------------
 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|  12.5k|		sc_log(ctx, "absolute path to EF(ODF) %s", sc_print_path(&tmppath));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1054|  12.5k|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1055|  12.5k|	}
 1056|      9|	else {
 1057|      9|		tmppath = p15card->file_odf->path;
 1058|      9|		sc_file_free(p15card->file_odf);
 1059|      9|		p15card->file_odf = NULL;
 1060|      9|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1061|      9|	}
 1062|       |
 1063|  12.5k|	if (err != SC_SUCCESS) {
  ------------------
  |  |   28|  12.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1063:6): [True: 11.5k, False: 1.03k]
  ------------------
 1064|  11.5k|		sc_log(ctx, "EF(ODF) not found in '%s'", sc_print_path(&tmppath));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1065|  11.5k|		goto end;
 1066|  11.5k|	}
 1067|       |
 1068|  1.03k|	len = p15card->file_odf->size;
 1069|  1.03k|	if (!len) {
  ------------------
  |  Branch (1069:6): [True: 166, False: 870]
  ------------------
 1070|    166|		sc_log(ctx, "EF(ODF) is empty");
  ------------------
  |  |   71|    166|#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|    166|		goto end;
 1072|    166|	}
 1073|    870|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|    870|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1073:6): [True: 31, False: 839]
  ------------------
 1074|     31|		sc_log(ctx, "EF(ODF) too large");
  ------------------
  |  |   71|     31|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1075|     31|		goto end;
 1076|     31|	}
 1077|    839|	buf = malloc(len);
 1078|    839|	if(buf == NULL) {
  ------------------
  |  Branch (1078:5): [True: 0, False: 839]
  ------------------
 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|    839|	err = -1; /* file state: not in cache */
 1084|    839|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1084:6): [True: 183, False: 656]
  ------------------
 1085|    183|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1086|    183|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|    183|#define SC_SUCCESS				0
  ------------------
  |  Branch (1086:7): [True: 1, False: 182]
  ------------------
 1087|      1|			err = (int)len;
 1088|    183|	}
 1089|    839|	if (err < 0) {
  ------------------
  |  Branch (1089:6): [True: 838, False: 1]
  ------------------
 1090|    838|		err = sc_read_binary(card, 0, buf, len, 0);
 1091|    838|		if (err < 2) {
  ------------------
  |  Branch (1091:7): [True: 382, False: 456]
  ------------------
 1092|    382|			if (err < 0) {
  ------------------
  |  Branch (1092:8): [True: 342, False: 40]
  ------------------
 1093|    342|				sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
  ------------------
  |  |   71|    342|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1094|    342|			} else {
 1095|     40|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     40|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1096|     40|				sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1097|     40|			}
 1098|    382|			goto end;
 1099|    382|		}
 1100|       |		/* sc_read_binary may return less than requested */
 1101|    456|		len = err;
 1102|       |
 1103|    456|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1103:7): [True: 97, False: 359]
  ------------------
 1104|     97|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1105|     97|		}
 1106|    456|	}
 1107|       |
 1108|    457|	if (parse_odf(buf, len, p15card)) {
  ------------------
  |  Branch (1108:6): [True: 201, False: 256]
  ------------------
 1109|    201|		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|    201|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1110|    201|		sc_log(ctx, "Unable to parse ODF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1111|    201|		goto end;
 1112|    201|	}
 1113|    256|	free(buf);
 1114|    256|	buf = NULL;
 1115|       |
 1116|    256|	sc_log(ctx, "The following DFs were found:");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1117|  1.39k|	for (df = p15card->df_list; df; df = df->next)
  ------------------
  |  Branch (1117:30): [True: 1.13k, False: 256]
  ------------------
 1118|  1.13k|		sc_log(ctx, "  DF type %u, path %s, index %u, count %d", df->type,
  ------------------
  |  |   71|  1.39k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1119|    256|				sc_print_path(&df->path), df->path.index, df->path.count);
 1120|       |
 1121|    256|	if (p15card->file_tokeninfo == NULL) {
  ------------------
  |  Branch (1121:6): [True: 256, False: 0]
  ------------------
 1122|    256|		sc_format_path("5032", &tmppath);
 1123|    256|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
 1124|    256|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    256|#define SC_SUCCESS				0
  ------------------
  |  Branch (1124:7): [True: 0, False: 256]
  ------------------
 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|    256|		sc_log(ctx, "absolute path to EF(TokenInfo) %s", sc_print_path(&tmppath));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1129|    256|	}
 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|    256|	err = sc_select_file(card, &tmppath, &p15card->file_tokeninfo);
 1137|    256|	if (err)   {
  ------------------
  |  Branch (1137:6): [True: 126, False: 130]
  ------------------
 1138|    126|		sc_log(ctx, "cannot select EF(TokenInfo) file: %s", sc_strerror(err));
  ------------------
  |  |   71|    126|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1139|    126|		goto end;
 1140|    126|	}
 1141|       |
 1142|    130|	len = p15card->file_tokeninfo->size;
 1143|    130|	if (!len) {
  ------------------
  |  Branch (1143:6): [True: 3, False: 127]
  ------------------
 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|    127|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|    127|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1147:6): [True: 27, False: 100]
  ------------------
 1148|     27|		sc_log(ctx, "EF(TokenInfo) too large");
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1149|     27|		goto end;
 1150|     27|	}
 1151|    100|	buf = malloc(len);
 1152|    100|	if(buf == NULL) {
  ------------------
  |  Branch (1152:5): [True: 0, False: 100]
  ------------------
 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|    100|	err = -1; /* file state: not in cache */
 1158|    100|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1158:6): [True: 29, False: 71]
  ------------------
 1159|     29|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1160|     29|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|     29|#define SC_SUCCESS				0
  ------------------
  |  Branch (1160:7): [True: 0, False: 29]
  ------------------
 1161|      0|			err = (int)len;
 1162|     29|	}
 1163|    100|	if (err < 0) {
  ------------------
  |  Branch (1163:6): [True: 100, False: 0]
  ------------------
 1164|    100|		err = sc_read_binary(card, 0, buf, len, 0);
 1165|    100|		if (err <= 2) {
  ------------------
  |  Branch (1165:7): [True: 53, False: 47]
  ------------------
 1166|     53|			if (err < 0)   {
  ------------------
  |  Branch (1166:8): [True: 43, False: 10]
  ------------------
 1167|     43|				sc_log(ctx, "read EF(TokenInfo) file error: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1168|     43|			} else {
 1169|     10|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     10|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1170|     10|				sc_log(ctx, "Invalid content of EF(TokenInfo): %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1171|     10|			}
 1172|     53|			goto end;
 1173|     53|		}
 1174|       |		/* sc_read_binary may return less than requested */
 1175|     47|		len = err;
 1176|       |
 1177|     47|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1177:7): [True: 9, False: 38]
  ------------------
 1178|      9|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1179|      9|		}
 1180|     47|	}
 1181|       |
 1182|     47|	memset(&tokeninfo, 0, sizeof(tokeninfo));
 1183|     47|	err = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t)err);
 1184|     47|	if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|     47|#define SC_SUCCESS				0
  ------------------
  |  Branch (1184:6): [True: 27, False: 20]
  ------------------
 1185|     27|		sc_log(ctx, "cannot parse TokenInfo content: %s", sc_strerror(err));
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1186|     27|		goto end;
 1187|     27|	}
 1188|       |
 1189|     20|	sc_pkcs15_clear_tokeninfo(p15card->tokeninfo);
 1190|     20|	*(p15card->tokeninfo) = tokeninfo;
 1191|       |
 1192|     20|	if (!p15card->tokeninfo->serial_number && 0 == card->serialnr.len) {
  ------------------
  |  Branch (1192:6): [True: 19, False: 1]
  |  Branch (1192:44): [True: 19, False: 0]
  ------------------
 1193|     19|		sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &card->serialnr);
 1194|     19|	}
 1195|       |
 1196|     20|	if (!p15card->tokeninfo->serial_number && card->serialnr.len)   {
  ------------------
  |  Branch (1196:6): [True: 19, False: 1]
  |  Branch (1196:44): [True: 15, False: 4]
  ------------------
 1197|     15|		char *serial = calloc(1, card->serialnr.len*2 + 1);
 1198|     15|		size_t ii;
 1199|     15|		if (!serial) {
  ------------------
  |  Branch (1199:7): [True: 0, False: 15]
  ------------------
 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|    312|		for(ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (1204:12): [True: 297, False: 15]
  ------------------
 1205|    297|			sprintf(serial + ii*2, "%02X", *(card->serialnr.value + ii));
 1206|       |
 1207|     15|		p15card->tokeninfo->serial_number = serial;
 1208|     15|		sc_log(ctx, "p15card->tokeninfo->serial_number %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   71|     15|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1209|     15|	}
 1210|       |
 1211|     20|	ok = 1;
 1212|  12.9k|end:
 1213|  12.9k|	if(buf != NULL)
  ------------------
  |  Branch (1213:5): [True: 683, False: 12.2k]
  ------------------
 1214|    683|		free(buf);
 1215|  12.9k|	if (!ok) {
  ------------------
  |  Branch (1215:6): [True: 12.9k, False: 20]
  ------------------
 1216|  12.9k|		sc_pkcs15_card_clear(p15card);
 1217|  12.9k|		if (err == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  12.9k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (1217:7): [True: 1.22k, False: 11.7k]
  ------------------
 1218|  1.22k|			err = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  1.22k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1219|  12.9k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  12.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.9k|	int _ret = r; \
  |  |  |  |  155|  12.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.9k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.7k, False: 227]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.9k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.9k|	return _ret; \
  |  |  |  |  163|  12.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1220|  12.9k|	}
 1221|       |
 1222|     20|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1223|     20|}
pkcs15_get_default_use_file_cache:
 1227|  13.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|  13.5k|	const char *card_drivers_with_file_cache[] = {
 1234|  13.5k|			"atrust-acos",
 1235|  13.5k|			"belpic",
 1236|  13.5k|			"cac1",
 1237|  13.5k|			"cac",
 1238|  13.5k|			"coolkey",
 1239|  13.5k|			"edo",
 1240|  13.5k|			"esteid2018",
 1241|  13.5k|			"esteid2025",
 1242|  13.5k|			"flex",
 1243|  13.5k|			"cyberflex",
 1244|  13.5k|			"gemsafeV1",
 1245|  13.5k|			"idprime",
 1246|  13.5k|			"itacns",
 1247|  13.5k|			"jpki",
 1248|  13.5k|			"MaskTech",
 1249|  13.5k|			"mcrd",
 1250|  13.5k|			"myeid",
 1251|  13.5k|			"npa",
 1252|  13.5k|			"nqapplet",
 1253|  13.5k|			"tcos",
 1254|  13.5k|			"dtrust",
 1255|  13.5k|			"lteid",
 1256|  13.5k|	};
 1257|       |
 1258|  13.5k|	if (NULL == card || NULL == card->driver || NULL == card->driver->short_name)
  ------------------
  |  Branch (1258:6): [True: 0, False: 13.5k]
  |  Branch (1258:22): [True: 0, False: 13.5k]
  |  Branch (1258:46): [True: 0, False: 13.5k]
  ------------------
 1259|      0|		return "no";
 1260|   245k|	for (size_t i = 0; i < (sizeof card_drivers_with_file_cache / sizeof *card_drivers_with_file_cache); i++) {
  ------------------
  |  Branch (1260:21): [True: 238k, False: 7.91k]
  ------------------
 1261|   238k|		if (0 == strcmp(card->driver->short_name, card_drivers_with_file_cache[i]))
  ------------------
  |  Branch (1261:7): [True: 5.60k, False: 232k]
  ------------------
 1262|  5.60k|			return "public";
 1263|   238k|	}
 1264|       |
 1265|  7.91k|	return "no";
 1266|  13.5k|}
sc_pkcs15_bind:
 1271|  13.5k|{
 1272|  13.5k|	struct sc_pkcs15_card *p15card = NULL;
 1273|  13.5k|	struct sc_context *ctx;
 1274|  13.5k|	scconf_block *conf_block = NULL;
 1275|  13.5k|	int r, emu_first, enable_emu;
 1276|  13.5k|	const char *use_file_cache;
 1277|  13.5k|	const char *pin_protected_certificate, *private_certificate;
 1278|       |
 1279|  13.5k|	if (card == NULL || p15card_out == NULL) {
  ------------------
  |  Branch (1279:6): [True: 0, False: 13.5k]
  |  Branch (1279:22): [True: 0, False: 13.5k]
  ------------------
 1280|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1281|      0|	}
 1282|  13.5k|	ctx = card->ctx;
 1283|       |
 1284|  13.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  13.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  13.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  13.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  13.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1285|  13.5k|	sc_log(ctx, "application(aid:'%s')", aid ? sc_dump_hex(aid->value, aid->len) : "empty");
  ------------------
  |  |   71|  27.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 13.5k]
  |  |  ------------------
  ------------------
 1286|       |
 1287|  13.5k|	p15card = sc_pkcs15_card_new();
 1288|  13.5k|	if (p15card == NULL)
  ------------------
  |  Branch (1288:6): [True: 0, False: 13.5k]
  ------------------
 1289|  13.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|  13.5k|	p15card->card = card;
 1292|  13.5k|	p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  13.5k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1293|  13.5k|	use_file_cache = pkcs15_get_default_use_file_cache(card);
 1294|  13.5k|	p15card->opts.use_pin_cache = 1;
 1295|  13.5k|	p15card->opts.pin_cache_counter = 10;
 1296|  13.5k|	p15card->opts.pin_cache_ignore_user_consent = 0;
 1297|  13.5k|	pin_protected_certificate = "protect";
 1298|  13.5k|	private_certificate = "";
 1299|       |
 1300|  13.5k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1301|  13.5k|	if (conf_block) {
  ------------------
  |  Branch (1301:6): [True: 0, False: 13.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|  13.5k|	if (0 == strcmp(use_file_cache, "yes")) {
  ------------------
  |  Branch (1312:6): [True: 0, False: 13.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|  13.5k|	} else if (0 == strcmp(use_file_cache, "public")) {
  ------------------
  |  Branch (1314:13): [True: 5.60k, False: 7.91k]
  ------------------
 1315|  5.60k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_PUBLIC_FILES;
  ------------------
  |  |  605|  5.60k|#define SC_PKCS15_OPTS_CACHE_PUBLIC_FILES		1
  ------------------
 1316|  7.91k|	} else if (0 == strcmp(use_file_cache, "no")) {
  ------------------
  |  Branch (1316:13): [True: 7.91k, False: 0]
  ------------------
 1317|  7.91k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  7.91k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1318|  7.91k|	}
 1319|       |
 1320|  13.5k|	if (0 == strcmp(pin_protected_certificate, "protect")) {
  ------------------
  |  Branch (1320:6): [True: 13.5k, False: 0]
  ------------------
 1321|  13.5k|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|  13.5k|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1322|  13.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|  13.5k|	if (0 == strcmp(private_certificate, "protect")) {
  ------------------
  |  Branch (1328:6): [True: 0, False: 13.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|  13.5k|	} else if (0 == strcmp(private_certificate, "ignore")) {
  ------------------
  |  Branch (1330:13): [True: 0, False: 13.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|  13.5k|	} else if (0 == strcmp(private_certificate, "declassify")) {
  ------------------
  |  Branch (1332:13): [True: 0, False: 13.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|  13.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|  13.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|  13.5k|			p15card->opts.use_file_cache, p15card->opts.use_pin_cache, p15card->opts.pin_cache_counter,
 1337|  13.5k|			p15card->opts.pin_cache_ignore_user_consent, p15card->opts.pin_protected_certificate);
 1338|       |
 1339|  13.5k|	r = sc_lock(card);
 1340|  13.5k|	if (r) {
  ------------------
  |  Branch (1340:6): [True: 0, False: 13.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|  13.5k|	enable_emu = scconf_get_bool(conf_block, "enable_pkcs15_emulation", 1);
 1347|  13.5k|	if (enable_emu) {
  ------------------
  |  Branch (1347:6): [True: 13.5k, False: 0]
  ------------------
 1348|  13.5k|		sc_log(ctx, "PKCS#15 emulation enabled");
  ------------------
  |  |   71|  13.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|  13.5k|		emu_first = scconf_get_bool(conf_block, "try_emulation_first", 0);
 1350|  13.5k|		if (emu_first || sc_pkcs15_is_emulation_only(card)) {
  ------------------
  |  Branch (1350:7): [True: 0, False: 13.5k]
  |  Branch (1350:20): [True: 3.04k, False: 10.4k]
  ------------------
 1351|  3.04k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1352|  3.04k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  3.04k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1352:8): [True: 1.57k, False: 1.47k]
  ------------------
 1353|  1.57k|				goto done;
 1354|  1.47k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1355|  1.47k|			if (r < 0)
  ------------------
  |  Branch (1355:8): [True: 1.46k, False: 9]
  ------------------
 1356|  1.46k|				goto error;
 1357|  10.4k|		} else {
 1358|  10.4k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1359|  10.4k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  10.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1359:8): [True: 224, False: 10.2k]
  ------------------
 1360|    224|				goto done;
 1361|  10.2k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1362|  10.2k|			if (r < 0)
  ------------------
  |  Branch (1362:8): [True: 6.02k, False: 4.22k]
  ------------------
 1363|  6.02k|				goto error;
 1364|  10.2k|		}
 1365|  13.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|  6.03k|done:
 1372|  6.03k|	*p15card_out = p15card;
 1373|  6.03k|	sc_unlock(card);
 1374|  6.03k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  6.03k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.03k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.03k|	int _ret = r; \
  |  |  |  |  155|  6.03k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.03k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.03k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 6.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.03k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.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|  6.03k|	return _ret; \
  |  |  |  |  163|  6.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1375|  7.48k|error:
 1376|  7.48k|	sc_unlock(card);
 1377|  7.48k|	sc_pkcs15_card_free(p15card);
 1378|  7.48k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  7.48k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.48k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.48k|	int _ret = r; \
  |  |  |  |  155|  7.48k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.48k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.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|  7.48k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.48k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.48k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.48k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  7.48k|	return _ret; \
  |  |  |  |  163|  7.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1379|  7.48k|}
sc_pkcs15_get_objects:
 1483|    166|{
 1484|    166|	return sc_pkcs15_get_objects_cond(p15card, type, NULL, NULL, ret, ret_size);
 1485|    166|}
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|    166|{
 1679|    166|	return __sc_pkcs15_search_objects(p15card, 0, type,
 1680|    166|			func, func_arg, ret, ret_size);
 1681|    166|}
sc_pkcs15_find_object_by_id:
 1687|  2.10k|{
 1688|  2.10k|	struct sc_pkcs15_search_key sk;
 1689|  2.10k|	int	r;
 1690|       |
 1691|  2.10k|	memset(&sk, 0, sizeof(sk));
 1692|  2.10k|	sk.id = id;
 1693|       |
 1694|  2.10k|	r = __sc_pkcs15_search_objects(p15card, 0, type, compare_obj_key, &sk, out, 1);
 1695|  2.10k|	if (r < 0)
  ------------------
  |  Branch (1695:6): [True: 0, False: 2.10k]
  ------------------
 1696|      0|		return r;
 1697|  2.10k|	if (r == 0)
  ------------------
  |  Branch (1697:6): [True: 930, False: 1.17k]
  ------------------
 1698|    930|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    930|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1699|  1.17k|	return 0;
 1700|  2.10k|}
sc_pkcs15_find_cert_by_id:
 1706|  1.23k|{
 1707|  1.23k|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_CERT, id, out);
  ------------------
  |  |  438|  1.23k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 1708|  1.23k|}
sc_pkcs15_find_pin_by_auth_id:
 1738|    867|{
 1739|    867|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_AUTH, id, out);
  ------------------
  |  |  444|    867|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
 1740|    867|}
sc_pkcs15_add_object:
 1930|  41.7k|{
 1931|  41.7k|	struct sc_pkcs15_object *p = p15card->obj_list;
 1932|       |
 1933|  41.7k|	if (!obj)
  ------------------
  |  Branch (1933:6): [True: 0, False: 41.7k]
  ------------------
 1934|      0|		return 0;
 1935|  41.7k|	obj->next = obj->prev = NULL;
 1936|  41.7k|	if (p15card->obj_list == NULL) {
  ------------------
  |  Branch (1936:6): [True: 5.54k, False: 36.1k]
  ------------------
 1937|  5.54k|		p15card->obj_list = obj;
 1938|  5.54k|		return 0;
 1939|  5.54k|	}
 1940|   561k|	while (p->next != NULL)
  ------------------
  |  Branch (1940:9): [True: 525k, False: 36.1k]
  ------------------
 1941|   525k|		p = p->next;
 1942|  36.1k|	p->next = obj;
 1943|  36.1k|	obj->prev = p;
 1944|       |
 1945|  36.1k|	return 0;
 1946|  41.7k|}
sc_pkcs15_free_object:
 1981|  41.7k|{
 1982|  41.7k|	if (!obj)
  ------------------
  |  Branch (1982:6): [True: 0, False: 41.7k]
  ------------------
 1983|      0|		return;
 1984|  41.7k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  41.7k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 1985|  4.83k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  4.83k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1985:2): [True: 4.83k, False: 36.8k]
  ------------------
 1986|  4.83k|		sc_pkcs15_free_prkey_info((sc_pkcs15_prkey_info_t *)obj->data);
 1987|  4.83k|		break;
 1988|  1.97k|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|  1.97k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1988:2): [True: 1.97k, False: 39.7k]
  ------------------
 1989|       |		/* This is normally passed to framework-pkcs15,
 1990|       |		 * but if something fails on the way, it would not get freed */
 1991|  1.97k|		if (obj->emulated) {
  ------------------
  |  Branch (1991:7): [True: 1.63k, False: 345]
  ------------------
 1992|  1.63k|			sc_pkcs15_free_pubkey(obj->emulated);
 1993|  1.63k|		}
 1994|  1.97k|		sc_pkcs15_free_pubkey_info((sc_pkcs15_pubkey_info_t *)obj->data);
 1995|  1.97k|		break;
 1996|  3.47k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  3.47k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1996:2): [True: 3.47k, False: 38.2k]
  ------------------
 1997|  3.47k|		sc_pkcs15_free_cert_info((sc_pkcs15_cert_info_t *)obj->data);
 1998|  3.47k|		break;
 1999|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (1999:2): [True: 0, False: 41.7k]
  ------------------
 2000|      0|		sc_pkcs15_free_skey_info((sc_pkcs15_skey_info_t *)obj->data);
 2001|      0|		break;
 2002|  23.9k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  23.9k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (2002:2): [True: 23.9k, False: 17.7k]
  ------------------
 2003|  23.9k|		sc_pkcs15_free_data_info((sc_pkcs15_data_info_t *)obj->data);
 2004|  23.9k|		break;
 2005|  7.48k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  7.48k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2005:2): [True: 7.48k, False: 34.2k]
  ------------------
 2006|  7.48k|		sc_pkcs15_free_auth_info((sc_pkcs15_auth_info_t *)obj->data);
 2007|  7.48k|		break;
 2008|      0|	default:
  ------------------
  |  Branch (2008:2): [True: 0, False: 41.7k]
  ------------------
 2009|      0|		free(obj->data);
 2010|  41.7k|	}
 2011|       |
 2012|  41.7k|	sc_pkcs15_free_object_content(obj);
 2013|       |
 2014|  41.7k|	free(obj);
 2015|  41.7k|}
sc_pkcs15_add_df:
 2020|  16.4k|{
 2021|  16.4k|	struct sc_pkcs15_df *p, *newdf;
 2022|       |
 2023|  16.4k|	newdf = calloc(1, sizeof(struct sc_pkcs15_df));
 2024|  16.4k|	if (newdf == NULL)
  ------------------
  |  Branch (2024:6): [True: 0, False: 16.4k]
  ------------------
 2025|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2026|  16.4k|	newdf->path = *path;
 2027|  16.4k|	newdf->type = type;
 2028|       |
 2029|  16.4k|	if (p15card->df_list == NULL) {
  ------------------
  |  Branch (2029:6): [True: 5.66k, False: 10.7k]
  ------------------
 2030|  5.66k|		p15card->df_list = newdf;
 2031|  5.66k|		return 0;
 2032|  5.66k|	}
 2033|       |
 2034|  10.7k|	p = p15card->df_list;
 2035|   285k|	while (p->next != NULL)
  ------------------
  |  Branch (2035:9): [True: 274k, False: 10.7k]
  ------------------
 2036|   274k|		p = p->next;
 2037|  10.7k|	p->next = newdf;
 2038|  10.7k|	newdf->prev = p;
 2039|       |
 2040|  10.7k|	return 0;
 2041|  16.4k|}
sc_pkcs15_parse_df:
 2136|  1.73k|{
 2137|  1.73k|	struct sc_context *ctx = p15card->card->ctx;
 2138|  1.73k|	unsigned char *buf;
 2139|  1.73k|	const unsigned char *p;
 2140|  1.73k|	size_t bufsize;
 2141|  1.73k|	int r;
 2142|  1.73k|	struct sc_pkcs15_object *obj = NULL;
 2143|  1.73k|	int (* func)(struct sc_pkcs15_card *, struct sc_pkcs15_object *,
 2144|  1.73k|		     const u8 **nbuf, size_t *nbufsize) = NULL;
 2145|       |
 2146|  1.73k|	sc_log(ctx, "called; path=%s, type=%d, enum=%d", sc_print_path(&df->path), df->type, df->enumerated);
  ------------------
  |  |   71|  1.73k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2147|       |
 2148|  1.73k|	if (df->enumerated)
  ------------------
  |  Branch (2148:6): [True: 0, False: 1.73k]
  ------------------
 2149|  1.73k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2150|       |
 2151|  1.73k|	switch (df->type) {
  ------------------
  |  Branch (2151:10): [True: 1.73k, False: 0]
  ------------------
 2152|    108|	case SC_PKCS15_PRKDF:
  ------------------
  |  |  488|    108|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (2152:2): [True: 108, False: 1.62k]
  ------------------
 2153|    108|		func = sc_pkcs15_decode_prkdf_entry;
 2154|    108|		break;
 2155|  1.23k|	case SC_PKCS15_PUKDF:
  ------------------
  |  |  489|  1.23k|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (2155:2): [True: 1.23k, False: 505]
  ------------------
 2156|  1.23k|		func = sc_pkcs15_decode_pukdf_entry;
 2157|  1.23k|		break;
 2158|      0|	case SC_PKCS15_SKDF:
  ------------------
  |  |  491|      0|#define SC_PKCS15_SKDF			3
  ------------------
  |  Branch (2158:2): [True: 0, False: 1.73k]
  ------------------
 2159|      0|		func = sc_pkcs15_decode_skdf_entry;
 2160|      0|		break;
 2161|    336|	case SC_PKCS15_CDF:
  ------------------
  |  |  492|    336|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (2161:2): [True: 336, False: 1.39k]
  ------------------
 2162|    336|	case SC_PKCS15_CDF_TRUSTED:
  ------------------
  |  |  493|    336|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
  |  Branch (2162:2): [True: 0, False: 1.73k]
  ------------------
 2163|    336|	case SC_PKCS15_CDF_USEFUL:
  ------------------
  |  |  494|    336|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
  |  Branch (2163:2): [True: 0, False: 1.73k]
  ------------------
 2164|    336|		func = sc_pkcs15_decode_cdf_entry;
 2165|    336|		break;
 2166|      0|	case SC_PKCS15_DODF:
  ------------------
  |  |  495|      0|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (2166:2): [True: 0, False: 1.73k]
  ------------------
 2167|      0|		func = sc_pkcs15_decode_dodf_entry;
 2168|      0|		break;
 2169|     61|	case SC_PKCS15_AODF:
  ------------------
  |  |  496|     61|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (2169:2): [True: 61, False: 1.67k]
  ------------------
 2170|     61|		func = sc_pkcs15_decode_aodf_entry;
 2171|     61|		break;
 2172|  1.73k|	}
 2173|  1.73k|	if (func == NULL) {
  ------------------
  |  Branch (2173:6): [True: 0, False: 1.73k]
  ------------------
 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.73k|	r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, 0);
 2178|  1.73k|	LOG_TEST_RET(ctx, r, "pkcs15 read file failed");
  ------------------
  |  |  174|  1.73k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.73k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.73k|	int _ret = (r); \
  |  |  |  |  168|  1.73k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.35k, False: 380]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.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|  1.35k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.35k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.35k|		return _ret; \
  |  |  |  |  172|  1.35k|	} \
  |  |  |  |  173|  1.73k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 380]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2179|       |
 2180|    380|	p = buf;
 2181|    380|	while (bufsize && *p != 0x00) {
  ------------------
  |  Branch (2181:9): [True: 346, False: 34]
  |  Branch (2181:20): [True: 328, False: 18]
  ------------------
 2182|       |
 2183|    328|		obj = calloc(1, sizeof(struct sc_pkcs15_object));
 2184|    328|		if (obj == NULL) {
  ------------------
  |  Branch (2184:7): [True: 0, False: 328]
  ------------------
 2185|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2186|      0|			goto ret;
 2187|      0|		}
 2188|    328|		r = func(p15card, obj, &p, &bufsize);
 2189|    328|		if (r) {
  ------------------
  |  Branch (2189:7): [True: 328, False: 0]
  ------------------
 2190|    328|			free(obj);
 2191|    328|			if (r == SC_ERROR_ASN1_END_OF_CONTENTS) {
  ------------------
  |  |   84|    328|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (2191:8): [True: 72, False: 256]
  ------------------
 2192|     72|				r = 0;
 2193|     72|				break;
 2194|     72|			}
 2195|    256|			sc_log(ctx, "%s: Error decoding DF entry", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2196|    256|			goto ret;
 2197|    328|		}
 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|    124|	};
 2213|       |
 2214|    124|	if (r > 0)
  ------------------
  |  Branch (2214:6): [True: 0, False: 124]
  ------------------
 2215|      0|		r = 0;
 2216|    380|ret:
 2217|    380|	df->enumerated = 1;
 2218|    380|	free(buf);
 2219|    380|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    380|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    380|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    380|	int _ret = r; \
  |  |  |  |  155|    380|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 380, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    380|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    256|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 256, False: 124]
  |  |  |  |  ------------------
  |  |  |  |  157|    380|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    380|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    380|	return _ret; \
  |  |  |  |  163|    380|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2220|    380|}
sc_pkcs15_read_file:
 2472|  15.2k|{
 2473|  15.2k|	struct sc_context *ctx;
 2474|  15.2k|	struct sc_file *file = NULL;
 2475|  15.2k|	unsigned char *data = NULL;
 2476|  15.2k|	size_t	len = 0, offset = 0;
 2477|  15.2k|	int	r;
 2478|       |
 2479|  15.2k|	if (p15card == NULL || p15card->card == NULL || in_path == NULL || buf == NULL) {
  ------------------
  |  Branch (2479:6): [True: 0, False: 15.2k]
  |  Branch (2479:25): [True: 0, False: 15.2k]
  |  Branch (2479:50): [True: 0, False: 15.2k]
  |  Branch (2479:69): [True: 0, False: 15.2k]
  ------------------
 2480|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2481|      0|	}
 2482|  15.2k|	ctx = p15card->card->ctx;
 2483|       |
 2484|  15.2k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  15.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  15.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  15.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  15.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 15.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2485|  15.2k|	sc_log(ctx, "path=%s, index=%u, count=%d", sc_print_path(in_path), in_path->index, in_path->count);
  ------------------
  |  |   71|  15.2k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2486|       |
 2487|  15.2k|	r = -1; /* file state: not in cache */
 2488|  15.2k|	if (p15card->opts.use_file_cache
  ------------------
  |  Branch (2488:6): [True: 6.70k, False: 8.50k]
  ------------------
 2489|  6.70k|	    && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|  6.70k|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2489:10): [True: 0, False: 6.70k]
  |  Branch (2489:77): [True: 6.70k, False: 0]
  ------------------
 2490|  6.70k|		r = sc_pkcs15_read_cached_file(p15card, in_path, &data, &len);
 2491|       |
 2492|  6.70k|		if (!r && in_path->aid.len > 0 && in_path->len >= 2)   {
  ------------------
  |  Branch (2492:7): [True: 469, False: 6.23k]
  |  Branch (2492:13): [True: 18, False: 451]
  |  Branch (2492:37): [True: 18, False: 0]
  ------------------
 2493|     18|			struct sc_path parent = *in_path;
 2494|       |
 2495|     18|			parent.len -= 2;
 2496|     18|			parent.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|     18|#define SC_PATH_TYPE_PATH		2
  ------------------
 2497|     18|			r = sc_select_file(p15card->card, &parent, NULL);
 2498|     18|		}
 2499|  6.70k|	}
 2500|       |
 2501|  15.2k|	if (r) {
  ------------------
  |  Branch (2501:6): [True: 14.7k, False: 461]
  ------------------
 2502|  14.7k|		r = sc_lock(p15card->card);
 2503|  14.7k|		if (r)
  ------------------
  |  Branch (2503:7): [True: 0, False: 14.7k]
  ------------------
 2504|      0|			goto fail;
 2505|  14.7k|		r = sc_select_file(p15card->card, in_path, &file);
 2506|  14.7k|		if (r)
  ------------------
  |  Branch (2506:7): [True: 10.5k, False: 4.21k]
  ------------------
 2507|  10.5k|			goto fail_unlock;
 2508|       |
 2509|       |		/* Handle the case where the ASN.1 Path object specified
 2510|       |		 * index and length values */
 2511|       |
 2512|  4.21k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  4.21k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2512:7): [True: 105, False: 4.11k]
  ------------------
 2513|       |
 2514|       |			// in_path->index: record_no
 2515|       |			// in_path->count: ignored!
 2516|       |
 2517|    105|			if(file->record_length > 0) {
  ------------------
  |  Branch (2517:7): [True: 89, False: 16]
  ------------------
 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|     16|				len = MAX_FILE_SIZE;
  ------------------
  |  |  229|     16|#define MAX_FILE_SIZE 65535
  ------------------
 2526|     16|			}
 2527|       |
 2528|    105|			if ((in_path->index <= 0) || (in_path->index > (int)(file->record_count))) {
  ------------------
  |  Branch (2528:8): [True: 66, False: 39]
  |  Branch (2528:33): [True: 1, False: 38]
  ------------------
 2529|     67|				sc_log(ctx, "  record number out of bounds: %d", in_path->index);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2530|     67|				r = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|     67|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
 2531|     67|				goto fail_unlock;
 2532|     67|			}
 2533|       |
 2534|  4.11k|		} else {
 2535|       |
 2536|  4.11k|			if (in_path->count < 0) {
  ------------------
  |  Branch (2536:8): [True: 2.39k, False: 1.71k]
  ------------------
 2537|  2.39k|				if (file->size)
  ------------------
  |  Branch (2537:9): [True: 2.18k, False: 205]
  ------------------
 2538|  2.18k|					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  229|  2.18k|#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: 2.18k]
  ------------------
 2539|    205|				else
 2540|    205|					len = 1024;
 2541|  2.39k|				offset = 0;
 2542|  2.39k|			}
 2543|  1.71k|			else {
 2544|  1.71k|				offset = in_path->index;
 2545|  1.71k|				len = in_path->count;
 2546|       |				/* Make sure we're within proper bounds */
 2547|  1.71k|				if (offset >= file->size || offset + len > file->size) {
  ------------------
  |  Branch (2547:9): [True: 16, False: 1.70k]
  |  Branch (2547:33): [True: 6, False: 1.69k]
  ------------------
 2548|     22|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     22|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2549|     22|					goto fail_unlock;
 2550|     22|				}
 2551|  1.71k|			}
 2552|  4.11k|		}
 2553|       |
 2554|  4.12k|		free(data);
 2555|  4.12k|		data = malloc(len);
 2556|  4.12k|		if (data == NULL) {
  ------------------
  |  Branch (2556:7): [True: 0, False: 4.12k]
  ------------------
 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|  4.12k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE_TLV) {
  ------------------
  |  |  225|  4.12k|#define SC_FILE_EF_LINEAR_VARIABLE_TLV	0x05
  ------------------
  |  Branch (2561:7): [True: 62, False: 4.06k]
  ------------------
 2562|     62|			unsigned int i;
 2563|     62|			size_t l, record_len;
 2564|     62|			unsigned char *head = data;
 2565|       |
 2566|    722|			for (i=1; ; i++) {
 2567|    722|				l = len - (head - data);
 2568|    722|				if (l > 256) {
  ------------------
  |  Branch (2568:9): [True: 456, False: 266]
  ------------------
 2569|    456|					l = 256;
 2570|    456|				}
 2571|    722|				r = sc_read_record(p15card->card, i, 0, head, l, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1305|    722|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2572|    722|				if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|    722|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (2572:9): [True: 6, False: 716]
  ------------------
 2573|      6|					break;
 2574|    716|				if (r < 0) {
  ------------------
  |  Branch (2574:9): [True: 51, False: 665]
  ------------------
 2575|     51|					goto fail_unlock;
 2576|     51|				}
 2577|    665|				if (r < 2)
  ------------------
  |  Branch (2577:9): [True: 4, False: 661]
  ------------------
 2578|      4|					break;
 2579|    661|				record_len = head[1];
 2580|    661|				if (record_len != 0xff) {
  ------------------
  |  Branch (2580:9): [True: 553, False: 108]
  ------------------
 2581|    553|					memmove(head, head+2, r-2);
 2582|    553|					head += (r-2);
 2583|    553|				}
 2584|    108|				else {
 2585|    108|					if (r < 4)
  ------------------
  |  Branch (2585:10): [True: 1, False: 107]
  ------------------
 2586|      1|						break;
 2587|    107|					memmove(head, head+4, r-4);
 2588|    107|					head += (r-4);
 2589|    107|				}
 2590|    661|			}
 2591|     11|			len = head-data;
 2592|     11|		}
 2593|  4.06k|		else if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  4.06k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2593:12): [True: 38, False: 4.02k]
  ------------------
 2594|     38|			r = sc_read_record(p15card->card, in_path->index, (unsigned)offset, data, len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1305|     38|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2595|     38|			if (r < 0) {
  ------------------
  |  Branch (2595:8): [True: 7, False: 31]
  ------------------
 2596|      7|				goto fail_unlock;
 2597|      7|			}
 2598|       |			/* sc_read_record may return less than requested */
 2599|     31|			len = r;
 2600|     31|		}
 2601|  4.02k|		else {
 2602|  4.02k|			unsigned long flags = 0;
 2603|  4.02k|			r = sc_read_binary(p15card->card, (unsigned)offset, data, len, &flags);
 2604|  4.02k|			if (r < 0) {
  ------------------
  |  Branch (2604:8): [True: 942, False: 3.08k]
  ------------------
 2605|    942|				goto fail_unlock;
 2606|    942|			}
 2607|       |			/* sc_read_binary may return less than requested */
 2608|  3.08k|			len = r;
 2609|       |
 2610|  3.08k|			if (flags & SC_FILE_FLAG_COMPRESSED_AUTO
  ------------------
  |  |  230|  6.17k|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  |  Branch (2610:8): [True: 336, False: 2.75k]
  ------------------
 2611|  2.75k|			    || flags & SC_FILE_FLAG_COMPRESSED_ZLIB
  ------------------
  |  |  231|  5.83k|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2611:11): [True: 0, False: 2.75k]
  ------------------
 2612|  2.75k|			    || flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|  2.75k|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2612:11): [True: 0, False: 2.75k]
  ------------------
 2613|    336|				unsigned char *decompressed_buf = NULL;
 2614|    336|				size_t decompressed_len = 0;
 2615|    336|				r = decompress_file(p15card->card, data, len, &decompressed_buf, &decompressed_len, flags);
 2616|    336|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    336|#define SC_SUCCESS				0
  ------------------
  |  Branch (2616:9): [True: 203, False: 133]
  ------------------
 2617|    203|					goto fail_unlock;
 2618|    203|				}
 2619|    133|				free(data);
 2620|    133|				data = decompressed_buf;
 2621|    133|				len = decompressed_len;
 2622|    133|			}
 2623|  3.08k|		}
 2624|  2.92k|		sc_unlock(p15card->card);
 2625|       |
 2626|  2.92k|		sc_file_free(file);
 2627|       |
 2628|  2.92k|		if (len && p15card->opts.use_file_cache
  ------------------
  |  Branch (2628:7): [True: 2.48k, False: 437]
  |  Branch (2628:14): [True: 474, False: 2.01k]
  ------------------
 2629|    474|		    && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|    474|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2629:11): [True: 0, False: 474]
  |  Branch (2629:78): [True: 474, False: 0]
  ------------------
 2630|    474|			sc_pkcs15_cache_file(p15card, in_path, data, len);
 2631|    474|		}
 2632|  2.92k|		if (len == 0) {
  ------------------
  |  Branch (2632:7): [True: 437, False: 2.48k]
  ------------------
 2633|    437|			free(data);
 2634|    437|			data = NULL;
 2635|    437|		}
 2636|  2.92k|	}
 2637|  3.38k|	*buf = data;
 2638|  3.38k|	*buflen = len;
 2639|  3.38k|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2640|       |
 2641|  11.8k|fail_unlock:
 2642|  11.8k|	sc_unlock(p15card->card);
 2643|  11.8k|fail:
 2644|  11.8k|	free(data);
 2645|  11.8k|	sc_file_free(file);
 2646|  11.8k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  11.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|  11.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2647|  11.8k|}
sc_pkcs15_compare_id:
 2652|  8.58k|{
 2653|  8.58k|	if (id1 == NULL || id2 == NULL)
  ------------------
  |  Branch (2653:6): [True: 0, False: 8.58k]
  |  Branch (2653:21): [True: 0, False: 8.58k]
  ------------------
 2654|      0|		return 0;
 2655|  8.58k|	if (id1->len != id2->len)
  ------------------
  |  Branch (2655:6): [True: 3.84k, False: 4.73k]
  ------------------
 2656|  3.84k|		return 0;
 2657|  4.73k|	return memcmp(id1->value, id2->value, id1->len) == 0;
 2658|  8.58k|}
sc_pkcs15_format_id:
 2663|  99.7k|{
 2664|  99.7k|	size_t len;
 2665|       |
 2666|  99.7k|	if (!id)
  ------------------
  |  Branch (2666:6): [True: 0, False: 99.7k]
  ------------------
 2667|      0|		return;
 2668|  99.7k|	len = sizeof(id->value);
 2669|       |
 2670|  99.7k|	if (sc_hex_to_bin(str, id->value, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  99.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2670:6): [True: 0, False: 99.7k]
  ------------------
 2671|      0|		id->len = 0;
 2672|  99.7k|	else
 2673|  99.7k|		id->len = len;
 2674|  99.7k|}
sc_pkcs15_print_id:
 2679|    531|{
 2680|    531|	static char buffer[256];
 2681|       |
 2682|    531|	sc_bin_to_hex(id->value, id->len, buffer, sizeof(buffer), '\0');
 2683|    531|	return buffer;
 2684|    531|}
sc_pkcs15_make_absolute_path:
 2697|  17.8k|{
 2698|       |	/* nothing to do if child has valid 'aid' */
 2699|  17.8k|	if (child->aid.len)
  ------------------
  |  Branch (2699:6): [True: 0, False: 17.8k]
  ------------------
 2700|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2701|       |
 2702|  17.8k|	if (parent->aid.len)   {
  ------------------
  |  Branch (2702:6): [True: 0, False: 17.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|  17.8k|	else if (parent->type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  17.8k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2717:11): [True: 156, False: 17.7k]
  ------------------
 2718|       |		/* child inherits parent's 'DF NAME' as 'aid' */
 2719|    156|		if (parent->len > sizeof(child->aid.value))
  ------------------
  |  Branch (2719:7): [True: 0, False: 156]
  ------------------
 2720|      0|			return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 2721|       |
 2722|    156|		memcpy(child->aid.value, parent->value, parent->len);
 2723|    156|		child->aid.len = parent->len;
 2724|       |
 2725|    156|		return SC_SUCCESS;
  ------------------
  |  |   28|    156|#define SC_SUCCESS				0
  ------------------
 2726|    156|	}
 2727|       |
 2728|       |	/* a 0 length path stays a 0 length path */
 2729|  17.7k|	if (child->len == 0)
  ------------------
  |  Branch (2729:6): [True: 119, False: 17.5k]
  ------------------
 2730|    119|		return SC_SUCCESS;
  ------------------
  |  |   28|    119|#define SC_SUCCESS				0
  ------------------
 2731|       |
 2732|  17.5k|	if (sc_compare_path_prefix(sc_get_mf_path(), child))
  ------------------
  |  Branch (2732:6): [True: 40, False: 17.5k]
  ------------------
 2733|     40|		return SC_SUCCESS;
  ------------------
  |  |   28|     40|#define SC_SUCCESS				0
  ------------------
 2734|       |
 2735|  17.5k|	return sc_concatenate_path(child, parent, child);
 2736|  17.5k|}
sc_pkcs15_free_object_content:
 2740|  42.6k|{
 2741|  42.6k|	if (obj->content.value && obj->content.len) {
  ------------------
  |  Branch (2741:6): [True: 902, False: 41.7k]
  |  Branch (2741:28): [True: 902, False: 0]
  ------------------
 2742|    902|		if (obj->content_free) {
  ------------------
  |  Branch (2742:7): [True: 902, False: 0]
  ------------------
 2743|    902|			obj->content_free(obj->content.value, obj->content.len);
 2744|    902|		} else {
 2745|      0|			free(obj->content.value);
 2746|      0|		}
 2747|    902|	}
 2748|       |	obj->content.value = NULL;
 2749|  42.6k|	obj->content.len = 0;
 2750|  42.6k|}
sc_pkcs15_allocate_object_content:
 2756|    902|{
 2757|    902|	unsigned char *tmp_buf;
 2758|       |
 2759|    902|	if (!obj)
  ------------------
  |  Branch (2759:6): [True: 0, False: 902]
  ------------------
 2760|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2761|       |
 2762|    902|	if (!value || !len)   {
  ------------------
  |  Branch (2762:6): [True: 0, False: 902]
  |  Branch (2762:16): [True: 0, False: 902]
  ------------------
 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|    902|	if (SC_PKCS15_TYPE_AUTH & obj->type
  ------------------
  |  |  444|    902|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2770:6): [True: 902, 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|    902|			|| SC_PKCS15_TYPE_PRKEY & obj->type) {
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2772:7): [True: 0, False: 0]
  ------------------
 2773|    902|		tmp_buf = sc_mem_secure_alloc(len);
 2774|    902|		obj->content_free = sc_mem_secure_free;
 2775|    902|	} else {
 2776|      0|		tmp_buf = malloc(len);
 2777|      0|	}
 2778|    902|	if (!tmp_buf)
  ------------------
  |  Branch (2778:6): [True: 0, False: 902]
  ------------------
 2779|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2780|       |
 2781|    902|	memcpy(tmp_buf, value, len);
 2782|       |
 2783|    902|	sc_pkcs15_free_object_content(obj);
 2784|       |
 2785|    902|	obj->content.value = tmp_buf;
 2786|    902|	obj->content.len = len;
 2787|       |
 2788|    902|	return SC_SUCCESS;
  ------------------
  |  |   28|    902|#define SC_SUCCESS				0
  ------------------
 2789|    902|}
sc_pkcs15_free_key_params:
 3094|  7.07k|{
 3095|  7.07k|	if (!params)
  ------------------
  |  Branch (3095:6): [True: 0, False: 7.07k]
  ------------------
 3096|      0|		return;
 3097|  7.07k|	if (params->data && params->free_params)
  ------------------
  |  Branch (3097:6): [True: 0, False: 7.07k]
  |  Branch (3097:22): [True: 0, False: 0]
  ------------------
 3098|      0|		params->free_params(params->data);
 3099|  7.07k|	else if (params->data)
  ------------------
  |  Branch (3099:11): [True: 0, False: 7.07k]
  ------------------
 3100|      0|		free(params->data);
 3101|       |
 3102|       |	params->data = NULL;
 3103|  7.07k|}
pkcs15.c:sc_pkcs15_clear_tokeninfo:
  748|  23.5k|{
  749|  23.5k|	if (!tokeninfo)
  ------------------
  |  Branch (749:6): [True: 0, False: 23.5k]
  ------------------
  750|      0|		return;
  751|       |
  752|  23.5k|	free(tokeninfo->label);
  753|  23.5k|	tokeninfo->label = NULL;
  754|  23.5k|	free(tokeninfo->serial_number);
  755|  23.5k|	tokeninfo->serial_number = NULL;
  756|  23.5k|	free(tokeninfo->manufacturer_id);
  757|  23.5k|	tokeninfo->manufacturer_id = NULL;
  758|  23.5k|	free(tokeninfo->last_update.gtime);
  759|  23.5k|	tokeninfo->last_update.gtime = NULL;
  760|  23.5k|	free(tokeninfo->preferred_language);
  761|  23.5k|	tokeninfo->preferred_language = NULL;
  762|  23.5k|	free(tokeninfo->profile_indication.name);
  763|  23.5k|	tokeninfo->profile_indication.name = NULL;
  764|  23.5k|	if (tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (764:6): [True: 9, False: 23.5k]
  ------------------
  765|      9|		unsigned i;
  766|     14|		for (i = 0; i < tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (766:15): [True: 5, False: 9]
  ------------------
  767|      5|			free(tokeninfo->seInfo[i]);
  768|      9|		free(tokeninfo->seInfo);
  769|       |		tokeninfo->seInfo = NULL;
  770|      9|	}
  771|  23.5k|}
pkcs15.c:sc_dup_app_info:
  902|    515|{
  903|    515|	struct sc_app_info *out = calloc(1, sizeof(struct sc_app_info));
  904|       |
  905|    515|	if (!out)
  ------------------
  |  Branch (905:6): [True: 0, False: 515]
  ------------------
  906|      0|		return NULL;
  907|       |
  908|    515|	memcpy(out, info, sizeof(struct sc_app_info));
  909|       |
  910|    515|	if (info->label) {
  ------------------
  |  Branch (910:6): [True: 10, False: 505]
  ------------------
  911|     10|		out->label = strdup(info->label);
  912|     10|		if (!out->label) {
  ------------------
  |  Branch (912:7): [True: 0, False: 10]
  ------------------
  913|      0|			free(out);
  914|      0|			return NULL;
  915|      0|		}
  916|     10|	} else
  917|    505|		out->label = NULL;
  918|       |
  919|    515|	out->ddo.value = malloc(info->ddo.len);
  920|    515|	if (!out->ddo.value) {
  ------------------
  |  Branch (920:6): [True: 0, False: 515]
  ------------------
  921|      0|		free(out->label);
  922|      0|		free(out);
  923|      0|		return NULL;
  924|      0|	}
  925|    515|	memcpy(out->ddo.value, info->ddo.value, info->ddo.len);
  926|    515|	out->ddo.len = info->ddo.len;
  927|       |
  928|    515|	return out;
  929|    515|}
pkcs15.c:parse_ddo:
  467|     46|{
  468|     46|	struct sc_context *ctx = p15card->card->ctx;
  469|     46|	struct sc_asn1_entry asn1_ddo[7];
  470|     46|	sc_path_t odf_path, ti_path, us_path;
  471|     46|	struct sc_iid iid;
  472|     46|	struct sc_aid aid;
  473|     46|	int r;
  474|       |
  475|     46|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     46|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     46|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     46|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     46|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 46]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  476|       |
  477|     46|	iid.len = sizeof(iid.value);
  478|     46|	aid.len = sizeof(aid.value);
  479|       |
  480|     46|	sc_copy_asn1_entry(c_asn1_ddo, asn1_ddo);
  481|     46|	sc_format_asn1_entry(asn1_ddo + 1, &odf_path, NULL, 0);
  482|     46|	sc_format_asn1_entry(asn1_ddo + 2, &ti_path, NULL, 0);
  483|     46|	sc_format_asn1_entry(asn1_ddo + 3, &us_path, NULL, 0);
  484|     46|	sc_format_asn1_entry(asn1_ddo + 4, iid.value, &iid.len, 0);
  485|     46|	sc_format_asn1_entry(asn1_ddo + 5, aid.value, &aid.len, 0);
  486|       |
  487|     46|	r = sc_asn1_decode(ctx, asn1_ddo, buf, buflen, NULL, NULL);
  488|     46|	LOG_TEST_RET(ctx, r, "DDO parsing 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: 12, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  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|     46|} 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: 14, False: 20]
  ------------------
  491|     14|		sc_file_free(p15card->file_odf);
  492|     14|		p15card->file_odf = sc_file_new();
  493|     14|		if (p15card->file_odf == NULL)
  ------------------
  |  Branch (493:7): [True: 0, False: 14]
  ------------------
  494|      0|			goto mem_err;
  495|     14|		p15card->file_odf->path = odf_path;
  496|     14|	}
  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: 3, False: 31]
  ------------------
  512|      3|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.IID '%s'", sc_dump_hex(iid.value, iid.len));
  ------------------
  |  |   70|      3|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  513|      3|		memcpy(&p15card->app->ddo.iid, &iid, sizeof(struct sc_iid));
  514|      3|	}
  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: 1, False: 33]
  ------------------
  458|      1|		sc_file_free(p15card->file_odf);
  459|      1|		p15card->file_odf = NULL;
  460|      1|		sc_file_free(p15card->file_tokeninfo);
  461|       |		p15card->file_tokeninfo = NULL;
  462|      1|	}
  463|     34|}
pkcs15.c:parse_odf:
  615|    457|{
  616|    457|	const unsigned char *p = buf;
  617|    457|	size_t left = buflen;
  618|    457|	int r, i, type;
  619|    457|	struct sc_path path;
  620|    457|	struct sc_asn1_entry asn1_obj_or_path[] = {
  621|    457|		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  174|    457|#define SC_ASN1_PATH			256
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  141|    457|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  162|    457|#define SC_ASN1_SEQUENCE                16
  ------------------
  622|    457|		{ NULL, 0, 0, 0, NULL, NULL }
  623|    457|	};
  624|    457|	struct sc_asn1_entry asn1_odf[10];
  625|       |
  626|    457|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  627|  4.57k|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (627:14): [True: 4.11k, False: 457]
  ------------------
  628|  4.11k|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  629|  3.68k|	while (left > 0) {
  ------------------
  |  Branch (629:9): [True: 3.63k, False: 49]
  ------------------
  630|  3.63k|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left, &p, &left);
  631|  3.63k|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|  3.63k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (631:7): [True: 207, False: 3.42k]
  ------------------
  632|    207|			break;
  633|  3.42k|		if (r < 0)
  ------------------
  |  Branch (633:7): [True: 200, False: 3.22k]
  ------------------
  634|    200|			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: 1, False: 3.22k]
  ------------------
  639|      1|				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|    256|	return 0;
  646|    457|}
pkcs15.c:__sc_pkcs15_search_objects:
 1402|  2.27k|{
 1403|  2.27k|	struct sc_pkcs15_object *obj = NULL;
 1404|  2.27k|	struct sc_pkcs15_df	*df = NULL;
 1405|  2.27k|	unsigned int	df_mask = 0;
 1406|  2.27k|	size_t		match_count = 0;
 1407|  2.27k|	int r;
 1408|       |
 1409|  2.27k|	if (type)
  ------------------
  |  Branch (1409:6): [True: 2.27k, False: 2]
  ------------------
 1410|  2.27k|		class_mask |= SC_PKCS15_TYPE_TO_CLASS(type);
  ------------------
  |  |  449|  2.27k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
 1411|       |
 1412|       |	/* Make sure the class mask we have makes sense */
 1413|  2.27k|	if (class_mask == 0
  ------------------
  |  Branch (1413:6): [True: 0, False: 2.27k]
  ------------------
 1414|  2.27k|			|| (class_mask & ~(
  ------------------
  |  Branch (1414:7): [True: 0, False: 2.27k]
  ------------------
 1415|  2.27k|					SC_PKCS15_SEARCH_CLASS_PRKEY |
  ------------------
  |  |  450|  2.27k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
 1416|  2.27k|					SC_PKCS15_SEARCH_CLASS_PUBKEY |
  ------------------
  |  |  451|  2.27k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
 1417|  2.27k|					SC_PKCS15_SEARCH_CLASS_SKEY |
  ------------------
  |  |  452|  2.27k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
 1418|  2.27k|					SC_PKCS15_SEARCH_CLASS_CERT |
  ------------------
  |  |  453|  2.27k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
 1419|  2.27k|					SC_PKCS15_SEARCH_CLASS_DATA |
  ------------------
  |  |  454|  2.27k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
 1420|  2.27k|					SC_PKCS15_SEARCH_CLASS_AUTH))) {
  ------------------
  |  |  455|  2.27k|#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.27k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PRKEY)
  ------------------
  |  |  450|  2.27k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
  |  Branch (1424:6): [True: 1, False: 2.27k]
  ------------------
 1425|      1|		df_mask |= (1 << SC_PKCS15_PRKDF);
  ------------------
  |  |  488|      1|#define SC_PKCS15_PRKDF			0
  ------------------
 1426|  2.27k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PUBKEY)
  ------------------
  |  |  451|  2.27k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
  |  Branch (1426:6): [True: 0, False: 2.27k]
  ------------------
 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.27k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_CERT)
  ------------------
  |  |  453|  2.27k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
  |  Branch (1428:6): [True: 1.24k, False: 1.03k]
  ------------------
 1429|  1.24k|		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  492|  1.24k|#define SC_PKCS15_CDF			4
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  493|  1.24k|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  494|  1.24k|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
 1430|  2.27k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_DATA)
  ------------------
  |  |  454|  2.27k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
  |  Branch (1430:6): [True: 160, False: 2.11k]
  ------------------
 1431|    160|		df_mask |= (1 << SC_PKCS15_DODF);
  ------------------
  |  |  495|    160|#define SC_PKCS15_DODF			7
  ------------------
 1432|  2.27k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_AUTH)
  ------------------
  |  |  455|  2.27k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
  |  Branch (1432:6): [True: 870, False: 1.40k]
  ------------------
 1433|    870|		df_mask |= (1 << SC_PKCS15_AODF);
  ------------------
  |  |  496|    870|#define SC_PKCS15_AODF			8
  ------------------
 1434|  2.27k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_SKEY)
  ------------------
  |  |  452|  2.27k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
  |  Branch (1434:6): [True: 0, False: 2.27k]
  ------------------
 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|  8.42k|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (1439:30): [True: 6.15k, False: 2.27k]
  ------------------
 1440|  6.15k|		if (!(df_mask & (1 << df->type)))   {
  ------------------
  |  Branch (1440:7): [True: 4.41k, False: 1.73k]
  ------------------
 1441|  4.41k|			continue;
 1442|  4.41k|		}
 1443|  1.73k|		if (df->enumerated)
  ------------------
  |  Branch (1443:7): [True: 1.73k, False: 0]
  ------------------
 1444|  1.73k|			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|  15.8k|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (1455:32): [True: 14.7k, False: 1.09k]
  ------------------
 1456|       |		/* Check object type */
 1457|  14.7k|		if (!(class_mask & SC_PKCS15_TYPE_TO_CLASS(obj->type)))
  ------------------
  |  |  449|  14.7k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
  |  Branch (1457:7): [True: 10.0k, False: 4.71k]
  ------------------
 1458|  10.0k|			continue;
 1459|  4.71k|		if (type != 0
  ------------------
  |  Branch (1459:7): [True: 4.71k, False: 0]
  ------------------
 1460|  4.71k|		 && obj->type != type
  ------------------
  |  Branch (1460:7): [True: 2.76k, False: 1.94k]
  ------------------
 1461|  2.76k|		 && (obj->type & SC_PKCS15_TYPE_CLASS_MASK) != type)
  ------------------
  |  |  416|  2.76k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1461:7): [True: 0, False: 2.76k]
  ------------------
 1462|      0|			continue;
 1463|       |
 1464|       |		/* Potential candidate, apply search function */
 1465|  4.71k|		if (func != NULL && func(obj, func_arg) <= 0)
  ------------------
  |  Branch (1465:7): [True: 2.76k, False: 1.94k]
  |  Branch (1465:23): [True: 1.59k, False: 1.17k]
  ------------------
 1466|  1.59k|			continue;
 1467|       |		/* Okay, we have a match. */
 1468|  3.12k|		match_count++;
 1469|  3.12k|		if (!ret || ret_size <= 0)
  ------------------
  |  Branch (1469:7): [True: 0, False: 3.12k]
  |  Branch (1469:15): [True: 0, False: 3.12k]
  ------------------
 1470|      0|			continue;
 1471|  3.12k|		ret[match_count-1] = obj;
 1472|  3.12k|		if (ret_size <= match_count)
  ------------------
  |  Branch (1472:7): [True: 1.17k, False: 1.94k]
  ------------------
 1473|  1.17k|			break;
 1474|  3.12k|	}
 1475|       |
 1476|  2.27k|	return (int)match_count;
 1477|  2.27k|}
pkcs15.c:compare_obj_key:
 1622|  2.76k|{
 1623|  2.76k|	struct sc_pkcs15_search_key *sk = (struct sc_pkcs15_search_key *) arg;
 1624|       |
 1625|  2.76k|	if (sk->id && !compare_obj_id(obj, sk->id))
  ------------------
  |  Branch (1625:6): [True: 2.76k, False: 0]
  |  Branch (1625:16): [True: 1.59k, False: 1.17k]
  ------------------
 1626|  1.59k|		return 0;
 1627|  1.17k|	if (sk->app_oid && !sc_obj_app_oid(obj, sk->app_oid))
  ------------------
  |  Branch (1627:6): [True: 0, False: 1.17k]
  |  Branch (1627:21): [True: 0, False: 0]
  ------------------
 1628|      0|		return 0;
 1629|  1.17k|	if (sk->usage_mask && !compare_obj_usage(obj, sk->usage_mask, sk->usage_value))
  ------------------
  |  Branch (1629:6): [True: 0, False: 1.17k]
  |  Branch (1629:24): [True: 0, False: 0]
  ------------------
 1630|      0|		return 0;
 1631|  1.17k|	if (sk->flags_mask && !compare_obj_flags(obj, sk->flags_mask, sk->flags_value))
  ------------------
  |  Branch (1631:6): [True: 0, False: 1.17k]
  |  Branch (1631:24): [True: 0, False: 0]
  ------------------
 1632|      0|		return 0;
 1633|  1.17k|	if (sk->match_reference && !compare_obj_reference(obj, sk->reference))
  ------------------
  |  Branch (1633:6): [True: 0, False: 1.17k]
  |  Branch (1633:29): [True: 0, False: 0]
  ------------------
 1634|      0|		return 0;
 1635|  1.17k|	if (sk->path && !compare_obj_path(obj, sk->path))
  ------------------
  |  Branch (1635:6): [True: 0, False: 1.17k]
  |  Branch (1635:18): [True: 0, False: 0]
  ------------------
 1636|      0|		return 0;
 1637|  1.17k|	if (
 1638|  1.17k|		sk->app_label && sk->label &&
  ------------------
  |  Branch (1638:3): [True: 0, False: 1.17k]
  |  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.17k|	) {
 1641|      0|		return 0;
 1642|      0|	}
 1643|       |
 1644|  1.17k|	return 1;
 1645|  1.17k|}
pkcs15.c:compare_obj_id:
 1490|  2.76k|{
 1491|  2.76k|	void *data = obj->data;
 1492|       |
 1493|  2.76k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  2.76k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1493:10): [True: 2.76k, False: 0]
  ------------------
 1494|  1.36k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  1.36k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1494:2): [True: 1.36k, False: 1.40k]
  ------------------
 1495|  1.36k|		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.76k]
  ------------------
 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.76k]
  ------------------
 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.76k]
  ------------------
 1501|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_skey_info *) data)->id, id);
 1502|  1.40k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  1.40k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (1502:2): [True: 1.40k, False: 1.36k]
  ------------------
 1503|  1.40k|		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.76k]
  ------------------
 1505|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_data_info *) data)->id, id);
 1506|  2.76k|	}
 1507|      0|	return 0;
 1508|  2.76k|}
pkcs15.c:sc_pkcs15_remove_objects:
 1965|  29.3k|{
 1966|  29.3k|	struct sc_pkcs15_object *cur = NULL, *next = NULL;
 1967|       |
 1968|  29.3k|	if (!p15card || !p15card->obj_list)
  ------------------
  |  Branch (1968:6): [True: 0, False: 29.3k]
  |  Branch (1968:18): [True: 23.8k, False: 5.54k]
  ------------------
 1969|  23.8k|		return;
 1970|  47.2k|	for (cur = p15card->obj_list; cur; cur = next)   {
  ------------------
  |  Branch (1970:32): [True: 41.7k, False: 5.54k]
  ------------------
 1971|  41.7k|		next = cur->next;
 1972|  41.7k|		sc_pkcs15_free_object(cur);
 1973|  41.7k|	}
 1974|       |
 1975|       |	p15card->obj_list = NULL;
 1976|  5.54k|}
pkcs15.c:sc_pkcs15_remove_dfs:
 2046|  29.3k|{
 2047|  29.3k|	struct sc_pkcs15_df *cur = NULL, *next = NULL;
 2048|       |
 2049|  29.3k|	if (!p15card || !p15card->df_list)
  ------------------
  |  Branch (2049:6): [True: 0, False: 29.3k]
  |  Branch (2049:18): [True: 23.7k, False: 5.66k]
  ------------------
 2050|  23.7k|		return;
 2051|       |
 2052|  22.0k|	for (cur = p15card->df_list; cur; cur = next)   {
  ------------------
  |  Branch (2052:31): [True: 16.4k, False: 5.66k]
  ------------------
 2053|  16.4k|		next = cur->next;
 2054|  16.4k|		free(cur);
 2055|  16.4k|	}
 2056|       |
 2057|       |	p15card->df_list = NULL;
 2058|  5.66k|}
pkcs15.c:sc_pkcs15_free_unusedspace:
 2281|  13.5k|{
 2282|  13.5k|	struct sc_pkcs15_unusedspace *cur = NULL, *next = NULL;
 2283|       |
 2284|  13.5k|	if (!p15card || !p15card->unusedspace_list)
  ------------------
  |  Branch (2284:6): [True: 0, False: 13.5k]
  |  Branch (2284:18): [True: 13.5k, False: 0]
  ------------------
 2285|  13.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|    336|{
 2422|    336|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    336|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    336|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    336|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    336|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 336]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2423|    336|#ifdef ENABLE_ZLIB
 2424|    336|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|    336|#define SC_SUCCESS				0
  ------------------
 2425|    336|	int method = 0;
 2426|       |
 2427|    336|	if (flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|    336|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2427:6): [True: 0, False: 336]
  ------------------
 2428|      0|		method = COMPRESSION_GZIP;
  ------------------
  |  |   28|      0|#define COMPRESSION_GZIP	2
  ------------------
 2429|    336|	} else if (flags & SC_FILE_FLAG_COMPRESSED_ZLIB) {
  ------------------
  |  |  231|    336|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2429:13): [True: 0, False: 336]
  ------------------
 2430|      0|		method = COMPRESSION_ZLIB;
  ------------------
  |  |   27|      0|#define COMPRESSION_ZLIB	1
  ------------------
 2431|    336|	} else {
 2432|    336|		method = COMPRESSION_AUTO;
  ------------------
  |  |   26|    336|#define COMPRESSION_AUTO	0
  ------------------
 2433|    336|	}
 2434|       |
 2435|    336|	rv = sc_decompress_alloc(out, outlen, buf, buflen, method);
 2436|    336|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    336|#define SC_SUCCESS				0
  ------------------
  |  Branch (2436:6): [True: 203, False: 133]
  ------------------
 2437|    203|		sc_log(card->ctx,  "Decompression failed: %d", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2438|    203|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  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|    203|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 203, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    203|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    203|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    203|	return _ret; \
  |  |  |  |  163|    203|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2439|    203|	}
 2440|    133|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    133|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    133|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    133|	int _ret = r; \
  |  |  |  |  155|    133|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 133, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    133|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 133]
  |  |  |  |  ------------------
  |  |  |  |  157|    133|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    133|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    133|	return _ret; \
  |  |  |  |  163|    133|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|    133|}

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

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

sc_get_version:
   59|  16.4k|{
   60|  16.4k|    return sc_version;
   61|  16.4k|}
sc_hex_to_bin:
   64|   383k|{
   65|   383k|	const char *sc_hex_to_bin_separators = " :";
   66|   383k|	if (in == NULL || out == NULL || outlen == NULL) {
  ------------------
  |  Branch (66:6): [True: 0, False: 383k]
  |  Branch (66:20): [True: 0, False: 383k]
  |  Branch (66:35): [True: 0, False: 383k]
  ------------------
   67|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   68|      0|	}
   69|       |
   70|   383k|	int byte_needs_nibble = 0;
   71|   383k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   383k|#define SC_SUCCESS				0
  ------------------
   72|   383k|	size_t left = *outlen;
   73|   383k|	u8 byte = 0;
   74|  6.20M|	while (*in != '\0' && 0 != left) {
  ------------------
  |  Branch (74:9): [True: 5.82M, False: 383k]
  |  Branch (74:24): [True: 5.82M, False: 0]
  ------------------
   75|  5.82M|		char c = *in++;
   76|  5.82M|		u8 nibble;
   77|  5.82M|		if      ('0' <= c && c <= '9')
  ------------------
  |  Branch (77:12): [True: 5.82M, False: 0]
  |  Branch (77:24): [True: 3.13M, False: 2.68M]
  ------------------
   78|  3.13M|			nibble = c - '0';
   79|  2.68M|		else if ('a' <= c && c <= 'f')
  ------------------
  |  Branch (79:12): [True: 512k, False: 2.17M]
  |  Branch (79:24): [True: 512k, False: 0]
  ------------------
   80|   512k|			nibble = c - 'a' + 10;
   81|  2.17M|		else if ('A' <= c && c <= 'F')
  ------------------
  |  Branch (81:12): [True: 741k, False: 1.42M]
  |  Branch (81:24): [True: 741k, False: 0]
  ------------------
   82|   741k|			nibble = c - 'A' + 10;
   83|  1.42M|		else {
   84|  1.42M|			if (strchr(sc_hex_to_bin_separators, (int) c)) {
  ------------------
  |  Branch (84:8): [True: 1.42M, False: 0]
  ------------------
   85|  1.42M|				if (byte_needs_nibble) {
  ------------------
  |  Branch (85:9): [True: 0, False: 1.42M]
  ------------------
   86|      0|					r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   87|      0|					goto err;
   88|      0|				}
   89|  1.42M|				continue;
   90|  1.42M|			}
   91|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|      0|			goto err;
   93|  1.42M|		}
   94|       |
   95|  4.39M|		if (byte_needs_nibble) {
  ------------------
  |  Branch (95:7): [True: 2.19M, False: 2.19M]
  ------------------
   96|  2.19M|			byte |= nibble;
   97|  2.19M|			*out++ = (u8) byte;
   98|  2.19M|			left--;
   99|  2.19M|			byte_needs_nibble = 0;
  100|  2.19M|		} else {
  101|  2.19M|			byte  = nibble << 4;
  102|  2.19M|			byte_needs_nibble = 1;
  103|  2.19M|		}
  104|  4.39M|	}
  105|       |
  106|   383k|	if (left == *outlen && 1 == byte_needs_nibble && 0 != left) {
  ------------------
  |  Branch (106:6): [True: 13.3k, False: 370k]
  |  Branch (106:25): [True: 7.88k, False: 5.47k]
  |  Branch (106:51): [True: 7.88k, False: 0]
  ------------------
  107|       |		/* no output written so far, but we have a valid nibble in the upper
  108|       |		 * bits. Allow this special case. */
  109|  7.88k|		*out = (u8) byte>>4;
  110|  7.88k|		left--;
  111|  7.88k|		byte_needs_nibble = 0;
  112|  7.88k|	}
  113|       |
  114|       |	/* for ease of implementation we only accept completely hexed bytes. */
  115|   383k|	if (byte_needs_nibble) {
  ------------------
  |  Branch (115:6): [True: 0, False: 383k]
  ------------------
  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|   383k|	while (*in != '\0') {
  ------------------
  |  Branch (121:9): [True: 0, False: 383k]
  ------------------
  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|   383k|	if (*in != '\0') {
  ------------------
  |  Branch (126:6): [True: 0, False: 383k]
  ------------------
  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|   383k|err:
  132|   383k|	*outlen -= left;
  133|   383k|	return r;
  134|   383k|}
sc_bin_to_hex:
  138|   336k|{
  139|   336k|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (139:6): [True: 0, False: 336k]
  |  Branch (139:20): [True: 0, False: 336k]
  ------------------
  140|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  141|      0|	}
  142|       |
  143|   336k|	if (in_sep > 0) {
  ------------------
  |  Branch (143:6): [True: 332k, False: 4.08k]
  ------------------
  144|   332k|		if (out_len < in_len*3 || out_len < 1)
  ------------------
  |  Branch (144:7): [True: 0, False: 332k]
  |  Branch (144:29): [True: 0, False: 332k]
  ------------------
  145|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  146|   332k|	} else {
  147|  4.08k|		if (out_len < in_len*2 + 1)
  ------------------
  |  Branch (147:7): [True: 11, False: 4.07k]
  ------------------
  148|     11|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     11|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  149|  4.08k|	}
  150|       |
  151|   336k|	const char hex[] = "0123456789abcdef";
  152|  4.24M|	while (in_len) {
  ------------------
  |  Branch (152:9): [True: 3.90M, False: 336k]
  ------------------
  153|  3.90M|		unsigned char value = *in++;
  154|  3.90M|		*out++ = hex[(value >> 4) & 0xF];
  155|  3.90M|		*out++ = hex[ value       & 0xF];
  156|  3.90M|		in_len--;
  157|  3.90M|		if (in_len && in_sep > 0)
  ------------------
  |  Branch (157:7): [True: 3.66M, False: 245k]
  |  Branch (157:17): [True: 3.64M, False: 17.8k]
  ------------------
  158|  3.64M|			*out++ = (char)in_sep;
  159|  3.90M|	}
  160|   336k|	*out = '\0';
  161|       |
  162|   336k|	return SC_SUCCESS;
  ------------------
  |  |   28|   336k|#define SC_SUCCESS				0
  ------------------
  163|   336k|}
ulong2bebytes:
  189|  97.4k|{
  190|  97.4k|	if (buf != NULL) {
  ------------------
  |  Branch (190:6): [True: 97.4k, False: 0]
  ------------------
  191|  97.4k|		buf[3] = (u8) (x & 0xff);
  192|  97.4k|		buf[2] = (u8) ((x >> 8) & 0xff);
  193|  97.4k|		buf[1] = (u8) ((x >> 16) & 0xff);
  194|  97.4k|		buf[0] = (u8) ((x >> 24) & 0xff);
  195|  97.4k|	}
  196|  97.4k|	return buf;
  197|  97.4k|}
ushort2bebytes:
  200|    301|{
  201|    301|	if (buf != NULL) {
  ------------------
  |  Branch (201:6): [True: 301, False: 0]
  ------------------
  202|    301|		buf[1] = (u8) (x & 0xff);
  203|    301|		buf[0] = (u8) ((x >> 8) & 0xff);
  204|    301|	}
  205|    301|	return buf;
  206|    301|}
bebytes2ulong:
  209|   140k|{
  210|   140k|	if (buf == NULL)
  ------------------
  |  Branch (210:6): [True: 0, False: 140k]
  ------------------
  211|      0|		return 0UL;
  212|   140k|	return (unsigned long)buf[0] << 24
  213|   140k|		| (unsigned long)buf[1] << 16
  214|   140k|		| (unsigned long)buf[2] << 8
  215|   140k|		| (unsigned long)buf[3];
  216|   140k|}
bebytes2ushort:
  219|   202k|{
  220|   202k|	if (buf == NULL)
  ------------------
  |  Branch (220:6): [True: 0, False: 202k]
  ------------------
  221|      0|		return 0U;
  222|   202k|	return (unsigned short)buf[0] << 8
  223|   202k|		| (unsigned short)buf[1];
  224|   202k|}
lebytes2ushort:
  227|  6.90k|{
  228|  6.90k|	if (buf == NULL)
  ------------------
  |  Branch (228:6): [True: 0, False: 6.90k]
  ------------------
  229|      0|		return 0U;
  230|  6.90k|	return (unsigned short)buf[1] << 8
  231|  6.90k|		| (unsigned short)buf[0];
  232|  6.90k|}
lebytes2ulong:
  235|    906|{
  236|    906|	if (buf == NULL)
  ------------------
  |  Branch (236:6): [True: 0, False: 906]
  ------------------
  237|      0|		return 0UL;
  238|    906|	return (unsigned long)buf[3] << 24
  239|    906|		| (unsigned long)buf[2] << 16
  240|    906|		| (unsigned long)buf[1] << 8
  241|    906|		| (unsigned long)buf[0];
  242|    906|}
set_string:
  245|  15.5k|{
  246|  15.5k|	if (strp == NULL) {
  ------------------
  |  Branch (246:6): [True: 0, False: 15.5k]
  ------------------
  247|      0|		return;
  248|      0|	}
  249|       |
  250|  15.5k|	free(*strp);
  251|  15.5k|	*strp = value ? strdup(value) : NULL;
  ------------------
  |  Branch (251:10): [True: 15.5k, False: 0]
  ------------------
  252|  15.5k|}
sc_init_oid:
  255|  55.5k|{
  256|  55.5k|	int ii;
  257|       |
  258|  55.5k|	if (!oid)
  ------------------
  |  Branch (258:6): [True: 0, False: 55.5k]
  ------------------
  259|      0|		return;
  260|   944k|	for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
  ------------------
  |  |   46|   944k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (260:13): [True: 889k, False: 55.5k]
  ------------------
  261|   889k|		oid->value[ii] = -1;
  262|  55.5k|}
sc_format_oid:
  265|  23.1k|{
  266|  23.1k|	int        ii, ret = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  23.1k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  267|  23.1k|	const char *p;
  268|  23.1k|	char       *q;
  269|       |
  270|  23.1k|	if (oid == NULL || in == NULL)
  ------------------
  |  Branch (270:6): [True: 0, False: 23.1k]
  |  Branch (270:21): [True: 0, False: 23.1k]
  ------------------
  271|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  272|       |
  273|  23.1k|	sc_init_oid(oid);
  274|       |
  275|  23.1k|	p = in;
  276|   215k|	for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++)   {
  ------------------
  |  |   46|   215k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (276:13): [True: 215k, False: 0]
  ------------------
  277|   215k|		oid->value[ii] = (int)strtol(p, &q, 10);
  278|   215k|		if (!*q)
  ------------------
  |  Branch (278:7): [True: 23.1k, False: 192k]
  ------------------
  279|  23.1k|			break;
  280|       |
  281|   192k|		if (!(q[0] == '.' && isdigit((unsigned char)q[1])))
  ------------------
  |  Branch (281:9): [True: 192k, False: 0]
  |  Branch (281:24): [True: 192k, False: 0]
  ------------------
  282|      0|			goto out;
  283|       |
  284|   192k|		p = q + 1;
  285|   192k|	}
  286|       |
  287|  23.1k|	if (!sc_valid_oid(oid))
  ------------------
  |  Branch (287:6): [True: 0, False: 23.1k]
  ------------------
  288|      0|		goto out;
  289|       |
  290|  23.1k|	ret = SC_SUCCESS;
  ------------------
  |  |   28|  23.1k|#define SC_SUCCESS				0
  ------------------
  291|  23.1k|out:
  292|  23.1k|	if (ret)
  ------------------
  |  Branch (292:6): [True: 0, False: 23.1k]
  ------------------
  293|      0|		sc_init_oid(oid);
  294|       |
  295|  23.1k|	return ret;
  296|  23.1k|}
sc_compare_oid:
  299|  76.9k|{
  300|  76.9k|	int i;
  301|       |
  302|  76.9k|	if (oid1 == NULL || oid2 == NULL) {
  ------------------
  |  Branch (302:6): [True: 0, False: 76.9k]
  |  Branch (302:22): [True: 0, False: 76.9k]
  ------------------
  303|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  304|      0|	}
  305|       |
  306|   189k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++)   {
  ------------------
  |  |   46|   189k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (306:14): [True: 189k, False: 0]
  ------------------
  307|   189k|		if (oid1->value[i] != oid2->value[i])
  ------------------
  |  Branch (307:7): [True: 74.5k, False: 114k]
  ------------------
  308|  74.5k|			return 0;
  309|   114k|		if (oid1->value[i] == -1)
  ------------------
  |  Branch (309:7): [True: 2.39k, False: 112k]
  ------------------
  310|  2.39k|			break;
  311|   114k|	}
  312|       |
  313|  2.39k|	return 1;
  314|  76.9k|}
sc_valid_oid:
  318|  24.7k|{
  319|  24.7k|	int ii;
  320|       |
  321|  24.7k|	if (!oid)
  ------------------
  |  Branch (321:6): [True: 0, False: 24.7k]
  ------------------
  322|      0|		return 0;
  323|  24.7k|	if (oid->value[0] == -1 || oid->value[1] == -1)
  ------------------
  |  Branch (323:6): [True: 0, False: 24.7k]
  |  Branch (323:29): [True: 0, False: 24.7k]
  ------------------
  324|      0|		return 0;
  325|  24.7k|	if (oid->value[0] > 2 || oid->value[1] > 39)
  ------------------
  |  Branch (325:6): [True: 0, False: 24.7k]
  |  Branch (325:27): [True: 0, False: 24.7k]
  ------------------
  326|      0|		return 0;
  327|  24.7k|	for (ii=0;ii<SC_MAX_OBJECT_ID_OCTETS;ii++)
  ------------------
  |  |   46|  24.7k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (327:12): [True: 24.7k, False: 0]
  ------------------
  328|  24.7k|		if (oid->value[ii])
  ------------------
  |  Branch (328:7): [True: 24.7k, False: 0]
  ------------------
  329|  24.7k|			break;
  330|  24.7k|	if (ii==SC_MAX_OBJECT_ID_OCTETS)
  ------------------
  |  |   46|  24.7k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (330:6): [True: 0, False: 24.7k]
  ------------------
  331|      0|		return 0;
  332|  24.7k|	return 1;
  333|  24.7k|}
sc_path_set:
  355|  25.9k|{
  356|  25.9k|	if (path == NULL || id == NULL || id_len == 0 || id_len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  25.9k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (356:6): [True: 0, False: 25.9k]
  |  Branch (356:22): [True: 0, False: 25.9k]
  |  Branch (356:36): [True: 0, False: 25.9k]
  |  Branch (356:51): [True: 0, False: 25.9k]
  ------------------
  357|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  358|       |
  359|  25.9k|	memset(path, 0, sizeof(*path));
  360|  25.9k|	memcpy(path->value, id, id_len);
  361|  25.9k|	path->len   = id_len;
  362|  25.9k|	path->type  = type;
  363|  25.9k|	path->index = idx;
  364|  25.9k|	path->count = count;
  365|       |
  366|  25.9k|	return SC_SUCCESS;
  ------------------
  |  |   28|  25.9k|#define SC_SUCCESS				0
  ------------------
  367|  25.9k|}
sc_format_path:
  370|   174k|{
  371|   174k|	int type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|   174k|#define SC_PATH_TYPE_PATH		2
  ------------------
  372|       |
  373|   174k|	if (path) {
  ------------------
  |  Branch (373:6): [True: 174k, False: 0]
  ------------------
  374|   174k|		memset(path, 0, sizeof(*path));
  375|   174k|		if (*str == 'i' || *str == 'I') {
  ------------------
  |  Branch (375:7): [True: 0, False: 174k]
  |  Branch (375:22): [True: 0, False: 174k]
  ------------------
  376|      0|			type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  377|      0|			str++;
  378|      0|		}
  379|   174k|		path->len = sizeof(path->value);
  380|   174k|		if (sc_hex_to_bin(str, path->value, &path->len) >= 0) {
  ------------------
  |  Branch (380:7): [True: 174k, False: 0]
  ------------------
  381|   174k|			path->type = type;
  382|   174k|		}
  383|   174k|		path->count = -1;
  384|   174k|	}
  385|   174k|}
sc_append_path_id:
  393|  43.4k|{
  394|  43.4k|	if (dest->len + idlen > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  43.4k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (394:6): [True: 1, False: 43.4k]
  ------------------
  395|      1|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  396|  43.4k|	memcpy(dest->value + dest->len, id, idlen);
  397|  43.4k|	dest->len += idlen;
  398|  43.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  43.4k|#define SC_SUCCESS				0
  ------------------
  399|  43.4k|}
sc_append_file_id:
  402|  43.3k|{
  403|  43.3k|	u8 id[2] = { fid >> 8, fid & 0xff };
  404|       |
  405|  43.3k|	return sc_append_path_id(dest, id, 2);
  406|  43.3k|}
sc_concatenate_path:
  409|  23.5k|{
  410|  23.5k|	sc_path_t tpath;
  411|       |
  412|  23.5k|	if (d == NULL || p1 == NULL || p2 == NULL)
  ------------------
  |  Branch (412:6): [True: 0, False: 23.5k]
  |  Branch (412:19): [True: 0, False: 23.5k]
  |  Branch (412:33): [True: 0, False: 23.5k]
  ------------------
  413|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  414|       |
  415|  23.5k|	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  47.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  23.5k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (415:6): [True: 0, False: 23.5k]
  |  Branch (415:42): [True: 0, False: 23.5k]
  ------------------
  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|  23.5k|	if (p1->len + p2->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  23.5k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (419:6): [True: 4, False: 23.5k]
  ------------------
  420|      4|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      4|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  421|       |
  422|  23.5k|	memset(&tpath, 0, sizeof(sc_path_t));
  423|  23.5k|	memcpy(tpath.value, p1->value, p1->len);
  424|  23.5k|	memcpy(tpath.value + p1->len, p2->value, p2->len);
  425|  23.5k|	tpath.len  = p1->len + p2->len;
  426|  23.5k|	tpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  23.5k|#define SC_PATH_TYPE_PATH		2
  ------------------
  427|       |	/* use 'index' and 'count' entry of the second path object */
  428|  23.5k|	tpath.index = p2->index;
  429|  23.5k|	tpath.count = p2->count;
  430|       |	/* the result is currently always as path */
  431|  23.5k|	tpath.type  = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  23.5k|#define SC_PATH_TYPE_PATH		2
  ------------------
  432|       |
  433|  23.5k|	*d = tpath;
  434|       |
  435|  23.5k|	return SC_SUCCESS;
  ------------------
  |  |   28|  23.5k|#define SC_SUCCESS				0
  ------------------
  436|  23.5k|}
sc_print_path:
  439|   251k|{
  440|   251k|	static char buffer[SC_MAX_PATH_STRING_SIZE + SC_MAX_AID_STRING_SIZE];
  441|       |
  442|   251k|	if (sc_path_print(buffer, sizeof(buffer), path) != SC_SUCCESS)
  ------------------
  |  |   28|   251k|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:6): [True: 0, False: 251k]
  ------------------
  443|      0|		buffer[0] = '\0';
  444|       |
  445|   251k|	return buffer;
  446|   251k|}
sc_path_print:
  449|   364k|{
  450|   364k|	size_t i;
  451|       |
  452|   364k|	if (buf == NULL || path == NULL)
  ------------------
  |  Branch (452:6): [True: 0, False: 364k]
  |  Branch (452:21): [True: 0, False: 364k]
  ------------------
  453|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  454|       |
  455|   364k|	if (buflen < path->len * 2 + path->aid.len * 2 + 3)
  ------------------
  |  Branch (455:6): [True: 665, False: 363k]
  ------------------
  456|    665|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|    665|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  457|       |
  458|   363k|	buf[0] = '\0';
  459|   363k|	if (path->aid.len)   {
  ------------------
  |  Branch (459:6): [True: 137k, False: 225k]
  ------------------
  460|  1.11M|		for (i = 0; i < path->aid.len; i++)
  ------------------
  |  Branch (460:15): [True: 972k, False: 137k]
  ------------------
  461|   972k|			snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->aid.value[i]);
  462|   137k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  463|   137k|	}
  464|       |
  465|  1.45M|	for (i = 0; i < path->len; i++)
  ------------------
  |  Branch (465:14): [True: 1.09M, False: 363k]
  ------------------
  466|  1.09M|		snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->value[i]);
  467|   363k|	if (!path->aid.len && path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|   225k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (467:6): [True: 225k, False: 137k]
  |  Branch (467:24): [True: 32.5k, False: 193k]
  ------------------
  468|  32.5k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  469|       |
  470|   363k|	return SC_SUCCESS;
  ------------------
  |  |   28|   363k|#define SC_SUCCESS				0
  ------------------
  471|   364k|}
sc_compare_path:
  474|  20.9k|{
  475|  20.9k|	return path1->len == path2->len
  ------------------
  |  Branch (475:9): [True: 16.9k, False: 3.95k]
  ------------------
  476|  16.9k|		&& !memcmp(path1->value, path2->value, path1->len);
  ------------------
  |  Branch (476:6): [True: 110, False: 16.8k]
  ------------------
  477|  20.9k|}
sc_compare_path_prefix:
  480|  17.6k|{
  481|  17.6k|	sc_path_t tpath;
  482|       |
  483|  17.6k|	if (prefix->len > path->len)
  ------------------
  |  Branch (483:6): [True: 2.91k, False: 14.7k]
  ------------------
  484|  2.91k|		return 0;
  485|       |
  486|  14.7k|	tpath     = *path;
  487|  14.7k|	tpath.len = prefix->len;
  488|       |
  489|  14.7k|	return sc_compare_path(&tpath, prefix);
  490|  17.6k|}
sc_get_mf_path:
  493|  21.6k|{
  494|  21.6k|	static const sc_path_t mf_path = {
  495|  21.6k|		{0x3f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2,
  496|  21.6k|		0,
  497|  21.6k|		0,
  498|  21.6k|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|  21.6k|#define SC_PATH_TYPE_PATH		2
  ------------------
  499|  21.6k|		{{0},0}
  500|  21.6k|	};
  501|  21.6k|	return &mf_path;
  502|  21.6k|}
sc_file_add_acl_entry:
  506|   168k|{
  507|   168k|	sc_acl_entry_t *p, *_new;
  508|       |
  509|   168k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   168k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (509:6): [True: 0, False: 168k]
  |  Branch (509:22): [True: 0, False: 168k]
  ------------------
  510|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  511|      0|	}
  512|       |
  513|   168k|	switch (method) {
  514|  49.5k|	case SC_AC_NEVER:
  ------------------
  |  |  163|  49.5k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  |  Branch (514:2): [True: 49.5k, False: 118k]
  ------------------
  515|  49.5k|		sc_file_clear_acl_entries(file, operation);
  516|  49.5k|		file->acl[operation] = (sc_acl_entry_t *) 1;
  517|  49.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  49.5k|#define SC_SUCCESS				0
  ------------------
  518|  8.42k|	case SC_AC_NONE:
  ------------------
  |  |  150|  8.42k|#define SC_AC_NONE			0x00000000
  ------------------
  |  Branch (518:2): [True: 8.42k, False: 159k]
  ------------------
  519|  8.42k|		sc_file_clear_acl_entries(file, operation);
  520|  8.42k|		file->acl[operation] = (sc_acl_entry_t *) 2;
  521|  8.42k|		return SC_SUCCESS;
  ------------------
  |  |   28|  8.42k|#define SC_SUCCESS				0
  ------------------
  522|  2.91k|	case SC_AC_UNKNOWN:
  ------------------
  |  |  162|  2.91k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  |  Branch (522:2): [True: 2.91k, False: 165k]
  ------------------
  523|  2.91k|		sc_file_clear_acl_entries(file, operation);
  524|  2.91k|		file->acl[operation] = (sc_acl_entry_t *) 3;
  525|  2.91k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.91k|#define SC_SUCCESS				0
  ------------------
  526|   107k|	default:
  ------------------
  |  Branch (526:2): [True: 107k, False: 60.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|   107k|		if (file->acl[operation] == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (530:7): [True: 12, False: 107k]
  ------------------
  531|     12|			return SC_SUCCESS;
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
  532|   107k|		if (file->acl[operation] == (sc_acl_entry_t *) 2
  ------------------
  |  Branch (532:7): [True: 1.19k, False: 106k]
  ------------------
  533|   106k|		 || file->acl[operation] == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (533:7): [True: 10, False: 106k]
  ------------------
  534|  1.20k|			file->acl[operation] = NULL;
  535|   168k|	}
  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|   138k|	for (p = file->acl[operation]; p != NULL; p = p->next) {
  ------------------
  |  Branch (539:33): [True: 33.4k, False: 104k]
  ------------------
  540|  33.4k|		if ((p->method == method) && (p->key_ref == key_ref))
  ------------------
  |  Branch (540:7): [True: 30.8k, False: 2.56k]
  |  Branch (540:32): [True: 2.49k, False: 28.3k]
  ------------------
  541|  2.49k|			return SC_SUCCESS;
  ------------------
  |  |   28|  2.49k|#define SC_SUCCESS				0
  ------------------
  542|  33.4k|	}
  543|       |
  544|   104k|	_new = malloc(sizeof(sc_acl_entry_t));
  545|   104k|	if (_new == NULL)
  ------------------
  |  Branch (545:6): [True: 0, False: 104k]
  ------------------
  546|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  547|   104k|	_new->method = method;
  548|   104k|	_new->key_ref = (unsigned)key_ref;
  549|   104k|	_new->next = NULL;
  550|       |
  551|   104k|	p = file->acl[operation];
  552|   104k|	if (p == NULL) {
  ------------------
  |  Branch (552:6): [True: 98.0k, False: 6.78k]
  ------------------
  553|  98.0k|		file->acl[operation] = _new;
  554|  98.0k|		return SC_SUCCESS;
  ------------------
  |  |   28|  98.0k|#define SC_SUCCESS				0
  ------------------
  555|  98.0k|	}
  556|  29.1k|	while (p->next != NULL)
  ------------------
  |  Branch (556:9): [True: 22.3k, False: 6.78k]
  ------------------
  557|  22.3k|		p = p->next;
  558|  6.78k|	p->next = _new;
  559|       |
  560|  6.78k|	return SC_SUCCESS;
  ------------------
  |  |   28|  6.78k|#define SC_SUCCESS				0
  ------------------
  561|   104k|}
sc_file_get_acl_entry:
  565|   502k|{
  566|   502k|	sc_acl_entry_t *p;
  567|   502k|	static const sc_acl_entry_t e_never = {
  568|   502k|		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  163|   502k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   502k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  569|   502k|	};
  570|   502k|	static const sc_acl_entry_t e_none = {
  571|   502k|		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  150|   502k|#define SC_AC_NONE			0x00000000
  ------------------
              		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   502k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  572|   502k|	};
  573|   502k|	static const sc_acl_entry_t e_unknown = {
  574|   502k|		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  162|   502k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   502k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  575|   502k|	};
  576|       |
  577|   502k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   502k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (577:6): [True: 0, False: 502k]
  |  Branch (577:22): [True: 0, False: 502k]
  ------------------
  578|      0|		return NULL;
  579|      0|	}
  580|       |
  581|   502k|	p = file->acl[operation];
  582|   502k|	if (p == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (582:6): [True: 990, False: 501k]
  ------------------
  583|    990|		return &e_never;
  584|   501k|	if (p == (sc_acl_entry_t *) 2)
  ------------------
  |  Branch (584:6): [True: 1.16k, False: 500k]
  ------------------
  585|  1.16k|		return &e_none;
  586|   500k|	if (p == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (586:6): [True: 1.16k, False: 499k]
  ------------------
  587|  1.16k|		return &e_unknown;
  588|       |
  589|   499k|	return file->acl[operation];
  590|   500k|}
sc_file_clear_acl_entries:
  593|  3.33M|{
  594|  3.33M|	sc_acl_entry_t *e;
  595|       |
  596|  3.33M|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  3.33M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (596:6): [True: 0, False: 3.33M]
  |  Branch (596:22): [True: 0, False: 3.33M]
  ------------------
  597|      0|		return;
  598|      0|	}
  599|       |
  600|  3.33M|	e = file->acl[operation];
  601|  3.33M|	if (e == (sc_acl_entry_t *) 1 ||
  ------------------
  |  Branch (601:6): [True: 49.3k, False: 3.28M]
  ------------------
  602|  3.28M|	    e == (sc_acl_entry_t *) 2 ||
  ------------------
  |  Branch (602:6): [True: 7.08k, False: 3.28M]
  ------------------
  603|  3.28M|	    e == (sc_acl_entry_t *) 3) {
  ------------------
  |  Branch (603:6): [True: 2.90k, False: 3.27M]
  ------------------
  604|  59.3k|		file->acl[operation] = NULL;
  605|  59.3k|		return;
  606|  59.3k|	}
  607|       |
  608|  3.38M|	while (e != NULL) {
  ------------------
  |  Branch (608:9): [True: 104k, False: 3.27M]
  ------------------
  609|   104k|		sc_acl_entry_t *tmp = e->next;
  610|   104k|		free(e);
  611|   104k|		e = tmp;
  612|   104k|	}
  613|       |	file->acl[operation] = NULL;
  614|  3.27M|}
sc_file_new:
  617|   105k|{
  618|   105k|	sc_file_t *file = (sc_file_t *)calloc(1, sizeof(sc_file_t));
  619|   105k|	if (file == NULL)
  ------------------
  |  Branch (619:6): [True: 0, False: 105k]
  ------------------
  620|      0|		return NULL;
  621|       |
  622|   105k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|   105k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  623|   105k|	return file;
  624|   105k|}
sc_file_free:
  627|   285k|{
  628|   285k|	unsigned int i;
  629|   285k|	if (file == NULL || !sc_file_valid(file))
  ------------------
  |  Branch (629:6): [True: 179k, False: 105k]
  |  Branch (629:22): [True: 0, False: 105k]
  ------------------
  630|   179k|		return;
  631|   105k|	file->magic = 0;
  632|  3.38M|	for (i = 0; i < SC_MAX_AC_OPS; i++)
  ------------------
  |  |  198|  3.38M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (632:14): [True: 3.27M, False: 105k]
  ------------------
  633|  3.27M|		sc_file_clear_acl_entries(file, i);
  634|   105k|	if (file->sec_attr)
  ------------------
  |  Branch (634:6): [True: 1.12k, False: 104k]
  ------------------
  635|  1.12k|		free(file->sec_attr);
  636|   105k|	if (file->prop_attr)
  ------------------
  |  Branch (636:6): [True: 841, False: 104k]
  ------------------
  637|    841|		free(file->prop_attr);
  638|   105k|	if (file->type_attr)
  ------------------
  |  Branch (638:6): [True: 2.42k, False: 103k]
  ------------------
  639|  2.42k|		free(file->type_attr);
  640|   105k|	if (file->encoded_content)
  ------------------
  |  Branch (640:6): [True: 0, False: 105k]
  ------------------
  641|      0|		free(file->encoded_content);
  642|   105k|	free(file);
  643|   105k|}
sc_file_dup:
  646|  16.2k|{
  647|  16.2k|	sc_file_t *newf;
  648|  16.2k|	const sc_acl_entry_t *e;
  649|  16.2k|	unsigned int op;
  650|       |
  651|  16.2k|	*dest = NULL;
  652|  16.2k|	if (!sc_file_valid(src))
  ------------------
  |  Branch (652:6): [True: 0, False: 16.2k]
  ------------------
  653|      0|		return;
  654|  16.2k|	newf = sc_file_new();
  655|  16.2k|	if (newf == NULL)
  ------------------
  |  Branch (655:6): [True: 0, False: 16.2k]
  ------------------
  656|      0|		return;
  657|  16.2k|	*dest = newf;
  658|       |
  659|  16.2k|	memcpy(&newf->path, &src->path, sizeof(struct sc_path));
  660|  16.2k|	memcpy(&newf->name, &src->name, sizeof(src->name));
  661|  16.2k|	newf->namelen = src->namelen;
  662|  16.2k|	newf->type    = src->type;
  663|  16.2k|	newf->shareable    = src->shareable;
  664|  16.2k|	newf->ef_structure = src->ef_structure;
  665|  16.2k|	newf->size    = src->size;
  666|  16.2k|	newf->id      = src->id;
  667|  16.2k|	newf->status  = src->status;
  668|   518k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|   518k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (668:15): [True: 502k, False: 16.2k]
  ------------------
  669|   502k|		newf->acl[op] = NULL;
  670|   502k|		e = sc_file_get_acl_entry(src, op);
  671|   502k|		if (e != NULL) {
  ------------------
  |  Branch (671:7): [True: 15.2k, False: 487k]
  ------------------
  672|  15.2k|			if (sc_file_add_acl_entry(newf, op, e->method, e->key_ref) < 0)
  ------------------
  |  Branch (672:8): [True: 0, False: 15.2k]
  ------------------
  673|      0|				goto err;
  674|  15.2k|		}
  675|   502k|	}
  676|  16.2k|	newf->record_length = src->record_length;
  677|  16.2k|	newf->record_count  = src->record_count;
  678|       |
  679|  16.2k|	if (sc_file_set_sec_attr(newf, src->sec_attr, src->sec_attr_len) < 0)
  ------------------
  |  Branch (679:6): [True: 0, False: 16.2k]
  ------------------
  680|      0|		goto err;
  681|  16.2k|	if (sc_file_set_prop_attr(newf, src->prop_attr, src->prop_attr_len) < 0)
  ------------------
  |  Branch (681:6): [True: 0, False: 16.2k]
  ------------------
  682|      0|		goto err;
  683|  16.2k|	if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
  ------------------
  |  Branch (683:6): [True: 0, False: 16.2k]
  ------------------
  684|      0|		goto err;
  685|  16.2k|	if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
  ------------------
  |  Branch (685:6): [True: 0, False: 16.2k]
  ------------------
  686|      0|		goto err;
  687|  16.2k|	return;
  688|  16.2k|err:
  689|      0|	sc_file_free(newf);
  690|       |	*dest = NULL;
  691|      0|}
sc_file_set_sec_attr:
  695|  17.7k|{
  696|  17.7k|	u8 *tmp;
  697|  17.7k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (697:6): [True: 0, False: 17.7k]
  ------------------
  698|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  699|      0|	}
  700|       |
  701|  17.7k|	if (sec_attr == NULL || sec_attr_len == 0) {
  ------------------
  |  Branch (701:6): [True: 16.1k, False: 1.51k]
  |  Branch (701:26): [True: 273, False: 1.23k]
  ------------------
  702|  16.4k|		if (file->sec_attr != NULL)
  ------------------
  |  Branch (702:7): [True: 66, False: 16.4k]
  ------------------
  703|     66|			free(file->sec_attr);
  704|  16.4k|		file->sec_attr = NULL;
  705|  16.4k|		file->sec_attr_len = 0;
  706|  16.4k|		return 0;
  707|  16.4k|	 }
  708|  1.23k|	tmp = (u8 *) realloc(file->sec_attr, sec_attr_len);
  709|  1.23k|	if (!tmp) {
  ------------------
  |  Branch (709:6): [True: 0, False: 1.23k]
  ------------------
  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.23k|	file->sec_attr = tmp;
  717|  1.23k|	memcpy(file->sec_attr, sec_attr, sec_attr_len);
  718|  1.23k|	file->sec_attr_len = sec_attr_len;
  719|       |
  720|  1.23k|	return 0;
  721|  1.23k|}
sc_file_set_prop_attr:
  725|  17.7k|{
  726|  17.7k|	u8 *tmp;
  727|  17.7k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (727:6): [True: 0, False: 17.7k]
  ------------------
  728|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  729|      0|	}
  730|       |
  731|  17.7k|	if (prop_attr == NULL || prop_attr_len == 0) {
  ------------------
  |  Branch (731:6): [True: 16.1k, False: 1.51k]
  |  Branch (731:27): [True: 497, False: 1.01k]
  ------------------
  732|  16.6k|		if (file->prop_attr != NULL)
  ------------------
  |  Branch (732:7): [True: 101, False: 16.5k]
  ------------------
  733|    101|			free(file->prop_attr);
  734|  16.6k|		file->prop_attr = NULL;
  735|  16.6k|		file->prop_attr_len = 0;
  736|  16.6k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.6k|#define SC_SUCCESS				0
  ------------------
  737|  16.6k|	 }
  738|  1.01k|	tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
  739|  1.01k|	if (!tmp) {
  ------------------
  |  Branch (739:6): [True: 0, False: 1.01k]
  ------------------
  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|  1.01k|	file->prop_attr = tmp;
  747|  1.01k|	memcpy(file->prop_attr, prop_attr, prop_attr_len);
  748|  1.01k|	file->prop_attr_len = prop_attr_len;
  749|       |
  750|  1.01k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.01k|#define SC_SUCCESS				0
  ------------------
  751|  1.01k|}
sc_file_set_type_attr:
  755|  18.3k|{
  756|  18.3k|	u8 *tmp;
  757|  18.3k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (757:6): [True: 0, False: 18.3k]
  ------------------
  758|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  759|      0|	}
  760|       |
  761|  18.3k|	if (type_attr == NULL || type_attr_len == 0) {
  ------------------
  |  Branch (761:6): [True: 15.4k, False: 2.90k]
  |  Branch (761:27): [True: 0, False: 2.90k]
  ------------------
  762|  15.4k|		if (file->type_attr != NULL)
  ------------------
  |  Branch (762:7): [True: 0, False: 15.4k]
  ------------------
  763|      0|			free(file->type_attr);
  764|  15.4k|		file->type_attr = NULL;
  765|  15.4k|		file->type_attr_len = 0;
  766|  15.4k|		return SC_SUCCESS;
  ------------------
  |  |   28|  15.4k|#define SC_SUCCESS				0
  ------------------
  767|  15.4k|	 }
  768|  2.90k|	tmp = (u8 *) realloc(file->type_attr, type_attr_len);
  769|  2.90k|	if (!tmp) {
  ------------------
  |  Branch (769:6): [True: 0, False: 2.90k]
  ------------------
  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.90k|	file->type_attr = tmp;
  777|  2.90k|	memcpy(file->type_attr, type_attr, type_attr_len);
  778|  2.90k|	file->type_attr_len = type_attr_len;
  779|       |
  780|  2.90k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.90k|#define SC_SUCCESS				0
  ------------------
  781|  2.90k|}
sc_file_set_content:
  786|  16.2k|{
  787|  16.2k|	u8 *tmp;
  788|  16.2k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (788:6): [True: 0, False: 16.2k]
  ------------------
  789|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  790|      0|	}
  791|       |
  792|  16.2k|	if (content == NULL || content_len == 0) {
  ------------------
  |  Branch (792:6): [True: 16.2k, False: 0]
  |  Branch (792:25): [True: 0, False: 0]
  ------------------
  793|  16.2k|		if (file->encoded_content != NULL)
  ------------------
  |  Branch (793:7): [True: 0, False: 16.2k]
  ------------------
  794|      0|			free(file->encoded_content);
  795|  16.2k|		file->encoded_content = NULL;
  796|  16.2k|		file->encoded_content_len = 0;
  797|  16.2k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.2k|#define SC_SUCCESS				0
  ------------------
  798|  16.2k|	}
  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|   191k|int sc_file_valid(const sc_file_t *file) {
  818|   191k|	if (file == NULL)
  ------------------
  |  Branch (818:6): [True: 0, False: 191k]
  ------------------
  819|      0|		return 0;
  820|   191k|	return file->magic == SC_FILE_MAGIC;
  ------------------
  |  |   57|   191k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  821|   191k|}
_sc_parse_atr:
  824|  16.4k|{
  825|  16.4k|	u8 *p = reader->atr.value;
  826|  16.4k|	int atr_len = (int) reader->atr.len;
  827|  16.4k|	int n_hist, x;
  828|  16.4k|	int tx[4] = {-1, -1, -1, -1};
  829|  16.4k|	int i, FI, DI;
  830|  16.4k|	const int Fi_table[] = {
  831|  16.4k|		372, 372, 558, 744, 1116, 1488, 1860, -1,
  832|  16.4k|		-1, 512, 768, 1024, 1536, 2048, -1, -1 };
  833|  16.4k|	const int f_table[] = {
  834|  16.4k|		40, 50, 60, 80, 120, 160, 200, -1,
  835|  16.4k|		-1, 50, 75, 100, 150, 200, -1, -1 };
  836|  16.4k|	const int Di_table[] = {
  837|  16.4k|		-1, 1, 2, 4, 8, 16, 32, -1,
  838|  16.4k|		12, 20, -1, -1, -1, -1, -1, -1 };
  839|       |
  840|  16.4k|	reader->atr_info.hist_bytes_len = 0;
  841|  16.4k|	reader->atr_info.hist_bytes = NULL;
  842|       |
  843|  16.4k|	if (atr_len == 0) {
  ------------------
  |  Branch (843:6): [True: 2.93k, False: 13.5k]
  ------------------
  844|  2.93k|		sc_log(reader->ctx, "empty ATR - card not present?\n");
  ------------------
  |  |   71|  2.93k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  845|  2.93k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.93k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  846|  2.93k|	}
  847|       |
  848|  13.5k|	if (p[0] != 0x3B && p[0] != 0x3F) {
  ------------------
  |  Branch (848:6): [True: 1.35k, False: 12.1k]
  |  Branch (848:22): [True: 1.27k, False: 84]
  ------------------
  849|  1.27k|		sc_log(reader->ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  850|  1.27k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.27k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  851|  1.27k|	}
  852|  12.2k|	n_hist = p[1] & 0x0F;
  853|  12.2k|	x = p[1] >> 4;
  854|  12.2k|	p += 2;
  855|  12.2k|	atr_len -= 2;
  856|  61.0k|	for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (856:14): [True: 48.8k, False: 12.1k]
  |  Branch (856:23): [True: 48.7k, False: 69]
  ------------------
  857|  48.7k|                if (x & (1 << i)) {
  ------------------
  |  Branch (857:21): [True: 33.2k, False: 15.5k]
  ------------------
  858|  33.2k|                        tx[i] = *p;
  859|  33.2k|                        p++;
  860|  33.2k|                        atr_len--;
  861|  33.2k|                } else
  862|  15.5k|                        tx[i] = -1;
  863|  48.7k|        }
  864|  12.2k|	if (tx[0] >= 0) {
  ------------------
  |  Branch (864:6): [True: 10.4k, False: 1.85k]
  ------------------
  865|  10.4k|		reader->atr_info.FI = FI = tx[0] >> 4;
  866|  10.4k|		reader->atr_info.DI = DI = tx[0] & 0x0F;
  867|  10.4k|		reader->atr_info.Fi = Fi_table[FI];
  868|  10.4k|		reader->atr_info.f = f_table[FI];
  869|  10.4k|		reader->atr_info.Di = Di_table[DI];
  870|  10.4k|	} else {
  871|  1.85k|		reader->atr_info.Fi = -1;
  872|  1.85k|		reader->atr_info.f = -1;
  873|  1.85k|		reader->atr_info.Di = -1;
  874|  1.85k|	}
  875|  12.2k|	if (tx[2] >= 0)
  ------------------
  |  Branch (875:6): [True: 8.41k, False: 3.84k]
  ------------------
  876|  8.41k|		reader->atr_info.N = tx[3];
  877|  3.84k|	else
  878|  3.84k|		reader->atr_info.N = -1;
  879|  28.3k|	while (tx[3] > 0 && tx[3] & 0xF0 && atr_len > 0) {
  ------------------
  |  Branch (879:9): [True: 16.6k, False: 11.7k]
  |  Branch (879:22): [True: 16.1k, False: 434]
  |  Branch (879:38): [True: 16.1k, False: 47]
  ------------------
  880|  16.1k|		x = tx[3] >> 4;
  881|  80.6k|		for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (881:15): [True: 64.5k, False: 16.1k]
  |  Branch (881:24): [True: 64.5k, False: 23]
  ------------------
  882|  64.5k|	                if (x & (1 << i)) {
  ------------------
  |  Branch (882:22): [True: 24.7k, False: 39.7k]
  ------------------
  883|  24.7k|	                        tx[i] = *p;
  884|  24.7k|	                        p++;
  885|  24.7k|	                        atr_len--;
  886|  24.7k|	                } else
  887|  39.7k|	                        tx[i] = -1;
  888|  64.5k|		}
  889|  16.1k|	}
  890|  12.2k|	if (atr_len <= 0)
  ------------------
  |  Branch (890:6): [True: 120, False: 12.1k]
  ------------------
  891|    120|		return SC_SUCCESS;
  ------------------
  |  |   28|    120|#define SC_SUCCESS				0
  ------------------
  892|  12.1k|	if (n_hist > atr_len)
  ------------------
  |  Branch (892:6): [True: 773, False: 11.3k]
  ------------------
  893|    773|		n_hist = atr_len;
  894|  12.1k|	reader->atr_info.hist_bytes_len = n_hist;
  895|  12.1k|	reader->atr_info.hist_bytes = p;
  896|  12.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  12.1k|#define SC_SUCCESS				0
  ------------------
  897|  12.2k|}
sc_mem_secure_alloc:
  900|  50.7k|{
  901|  50.7k|	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|  50.7k|	p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  910|  50.7k|	if (p != NULL) {
  ------------------
  |  Branch (910:6): [True: 50.7k, False: 0]
  ------------------
  911|  50.7k|		mlock(p, len);
  912|  50.7k|	}
  913|  50.7k|#endif
  914|       |
  915|  50.7k|	return p;
  916|  50.7k|}
sc_mem_secure_free:
  919|  50.7k|{
  920|       |#ifdef _WIN32
  921|       |	VirtualUnlock(ptr, len);
  922|       |	VirtualFree(ptr, 0, MEM_RELEASE);
  923|       |#else
  924|  50.7k|	munlock(ptr, len);
  925|  50.7k|	munmap(ptr, len);
  926|  50.7k|#endif
  927|  50.7k|}
sc_mem_clear:
  930|   108k|{
  931|   108k|	if (len > 0)   {
  ------------------
  |  Branch (931:6): [True: 107k, False: 612]
  ------------------
  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|   107k|	}
  944|   108k|}
sc_compacttlv_find_tag:
 1058|  1.48k|{
 1059|  1.48k|	if (buf != NULL) {
  ------------------
  |  Branch (1059:6): [True: 1.48k, False: 0]
  ------------------
 1060|  1.48k|		size_t idx;
 1061|  1.48k|		u8 plain_tag = tag & 0xF0;
 1062|  1.48k|		size_t expected_len = tag & 0x0F;
 1063|       |
 1064|  12.8k|		for (idx = 0; idx < len; idx++) {
  ------------------
  |  Branch (1064:17): [True: 11.7k, False: 1.03k]
  ------------------
 1065|  11.7k|			u8 ctag = buf[idx] & 0xF0;
 1066|  11.7k|			size_t ctag_len = buf[idx] & 0x0F;
 1067|  11.7k|			if (ctag == plain_tag && idx + ctag_len < len &&
  ------------------
  |  Branch (1067:8): [True: 1.15k, False: 10.6k]
  |  Branch (1067:29): [True: 1.13k, False: 16]
  ------------------
 1068|  1.13k|					(expected_len == 0 || expected_len == ctag_len)) {
  ------------------
  |  Branch (1068:7): [True: 227, False: 910]
  |  Branch (1068:28): [True: 225, False: 685]
  ------------------
 1069|    452|				if (outlen != NULL)
  ------------------
  |  Branch (1069:9): [True: 227, False: 225]
  ------------------
 1070|    227|					*outlen = ctag_len;
 1071|    452|				return buf + (idx + 1);
 1072|    452|			}
 1073|  11.3k|			idx += ctag_len;
 1074|  11.3k|		}
 1075|  1.48k|	}
 1076|  1.03k|	return NULL;
 1077|  1.48k|}
sc_mutex_create:
 1082|  32.9k|{
 1083|  32.9k|	if (ctx == NULL)
  ------------------
  |  Branch (1083:6): [True: 0, False: 32.9k]
  ------------------
 1084|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1085|  32.9k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->create_mutex != NULL)
  ------------------
  |  Branch (1085:6): [True: 0, False: 32.9k]
  |  Branch (1085:33): [True: 0, False: 0]
  ------------------
 1086|      0|		return ctx->thread_ctx->create_mutex(mutex);
 1087|  32.9k|	else
 1088|  32.9k|		return SC_SUCCESS;
  ------------------
  |  |   28|  32.9k|#define SC_SUCCESS				0
  ------------------
 1089|  32.9k|}
sc_mutex_lock:
 1092|  1.52M|{
 1093|  1.52M|	if (ctx == NULL)
  ------------------
  |  Branch (1093:6): [True: 0, False: 1.52M]
  ------------------
 1094|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1095|  1.52M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->lock_mutex != NULL)
  ------------------
  |  Branch (1095:6): [True: 0, False: 1.52M]
  |  Branch (1095:33): [True: 0, False: 0]
  ------------------
 1096|      0|		return ctx->thread_ctx->lock_mutex(mutex);
 1097|  1.52M|	else
 1098|  1.52M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.52M|#define SC_SUCCESS				0
  ------------------
 1099|  1.52M|}
sc_mutex_unlock:
 1102|  1.52M|{
 1103|  1.52M|	if (ctx == NULL)
  ------------------
  |  Branch (1103:6): [True: 0, False: 1.52M]
  ------------------
 1104|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1105|  1.52M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->unlock_mutex != NULL)
  ------------------
  |  Branch (1105:6): [True: 0, False: 1.52M]
  |  Branch (1105:33): [True: 0, False: 0]
  ------------------
 1106|      0|		return ctx->thread_ctx->unlock_mutex(mutex);
 1107|  1.52M|	else
 1108|  1.52M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.52M|#define SC_SUCCESS				0
  ------------------
 1109|  1.52M|}

sc_decipher:
   37|  2.94k|{
   38|  2.94k|	int r;
   39|       |
   40|  2.94k|	if (card == NULL) {
  ------------------
  |  Branch (40:6): [True: 0, False: 2.94k]
  ------------------
   41|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   42|      0|	}
   43|  2.94k|	if (crgram == NULL || out == NULL) {
  ------------------
  |  Branch (43:6): [True: 570, False: 2.37k]
  |  Branch (43:24): [True: 0, False: 2.37k]
  ------------------
   44|    570|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    570|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    570|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    570|	int _ret = r; \
  |  |  |  |  155|    570|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 570, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    570|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    570|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 570, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    570|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    570|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    570|	return _ret; \
  |  |  |  |  163|    570|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   45|    570|	}
   46|  2.37k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.37k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.37k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.37k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.37k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.37k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   47|  2.37k|	if (card->ops->decipher == NULL)
  ------------------
  |  Branch (47:6): [True: 0, False: 2.37k]
  ------------------
   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.37k|	r = card->ops->decipher(card, crgram, crgram_len, out, outlen);
   50|  2.37k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.37k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.37k|	int _ret = r; \
  |  |  155|  2.37k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.04k, False: 324]
  |  |  ------------------
  |  |  156|  2.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.86k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.86k, False: 182]
  |  |  ------------------
  |  |  157|  2.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.04k|	} else { \
  |  |  159|    324|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    324|			"returning with: %d\n", _ret); \
  |  |  161|    324|	} \
  |  |  162|  2.37k|	return _ret; \
  |  |  163|  2.37k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   51|  2.37k|}
sc_compute_signature:
   56|  5.98k|{
   57|  5.98k|	int r;
   58|       |
   59|  5.98k|	if (card == NULL) {
  ------------------
  |  Branch (59:6): [True: 0, False: 5.98k]
  ------------------
   60|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   61|      0|	}
   62|  5.98k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  5.98k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.98k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.98k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.98k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.98k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|  5.98k|	if (card->ops->compute_signature == NULL)
  ------------------
  |  Branch (63:6): [True: 0, False: 5.98k]
  ------------------
   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.98k|	r = card->ops->compute_signature(card, data, datalen, out, outlen);
   66|  5.98k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  5.98k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  5.98k|	int _ret = r; \
  |  |  155|  5.98k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 5.63k, False: 348]
  |  |  ------------------
  |  |  156|  5.63k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  5.38k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 5.38k, False: 249]
  |  |  ------------------
  |  |  157|  5.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  5.63k|	} else { \
  |  |  159|    348|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    348|			"returning with: %d\n", _ret); \
  |  |  161|    348|	} \
  |  |  162|  5.98k|	return _ret; \
  |  |  163|  5.98k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   67|  5.98k|}
sc_set_security_env:
  102|  13.2k|{
  103|  13.2k|	int r;
  104|       |
  105|  13.2k|	if (card == NULL) {
  ------------------
  |  Branch (105:6): [True: 0, False: 13.2k]
  ------------------
  106|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  107|      0|	}
  108|  13.2k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  13.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  13.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  13.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  13.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  109|  13.2k|	if (card->ops->set_security_env == NULL)
  ------------------
  |  Branch (109:6): [True: 0, False: 13.2k]
  ------------------
  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|  13.2k|	r = card->ops->set_security_env(card, env, se_num);
  112|  13.2k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  13.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  13.2k|	int _ret = r; \
  |  |  155|  13.2k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 13.2k, False: 0]
  |  |  ------------------
  |  |  156|  13.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  4.34k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4.34k, False: 8.92k]
  |  |  ------------------
  |  |  157|  13.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  13.2k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  13.2k|	return _ret; \
  |  |  163|  13.2k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  113|  13.2k|}
sc_restore_security_env:
  116|     40|{
  117|     40|	int r;
  118|       |
  119|     40|	if (card == NULL) {
  ------------------
  |  Branch (119:6): [True: 0, False: 40]
  ------------------
  120|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  121|      0|	}
  122|     40|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     40|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     40|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     40|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     40|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 40]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  123|     40|	if (card->ops->restore_security_env == NULL)
  ------------------
  |  Branch (123:6): [True: 0, False: 40]
  ------------------
  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|     40|	r = card->ops->restore_security_env(card, se_num);
  126|     40|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     40|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     40|	int _ret = r; \
  |  |  155|     40|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 40, False: 0]
  |  |  ------------------
  |  |  156|     40|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     24|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 24, False: 16]
  |  |  ------------------
  |  |  157|     40|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     40|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     40|	return _ret; \
  |  |  163|     40|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  127|     40|}
sc_verify:
  131|  1.08k|{
  132|  1.08k|	struct sc_pin_cmd_data data;
  133|       |
  134|  1.08k|	memset(&data, 0, sizeof(data));
  135|  1.08k|	data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  422|  1.08k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  136|  1.08k|	data.pin_type = type;
  137|  1.08k|	data.pin_reference = ref;
  138|  1.08k|	data.pin1.data = pin;
  139|  1.08k|	data.pin1.len = pinlen;
  140|       |
  141|  1.08k|	int r = sc_pin_cmd(card, &data);
  142|  1.08k|	if (tries_left)
  ------------------
  |  Branch (142:6): [True: 1.08k, False: 0]
  ------------------
  143|  1.08k|		*tries_left = data.pin1.tries_left;
  144|       |
  145|  1.08k|	return r;
  146|  1.08k|}
sc_pin_cmd:
  204|  10.8k|{
  205|  10.8k|	int r, debug;
  206|       |
  207|  10.8k|	if (card == NULL) {
  ------------------
  |  Branch (207:6): [True: 0, False: 10.8k]
  ------------------
  208|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  209|      0|	}
  210|  10.8k|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|       |
  212|  10.8k|	debug = card->ctx->debug;
  213|  10.8k|	if (data->cmd != SC_PIN_CMD_GET_INFO
  ------------------
  |  |  425|  21.7k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (213:6): [True: 2.90k, False: 7.99k]
  ------------------
  214|  2.90k|			&& card->ctx->debug < SC_LOG_DEBUG_PIN) {
  ------------------
  |  Branch (214:7): [True: 2.90k, False: 0]
  ------------------
  215|  2.90k|		card->ctx->debug = 0;
  216|  2.90k|	}
  217|       |
  218|  10.8k|	if (card->ops->pin_cmd) {
  ------------------
  |  Branch (218:6): [True: 10.8k, False: 0]
  ------------------
  219|  10.8k|		r = card->ops->pin_cmd(card, data);
  220|  10.8k|	} else if (!(data->flags & SC_PIN_CMD_USE_PINPAD)) {
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (220:13): [True: 0, False: 0]
  ------------------
  221|       |		/* Card driver doesn't support new style pin_cmd, fall
  222|       |		 * back to old interface */
  223|       |
  224|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  225|      0|		switch (data->cmd) {
  ------------------
  |  Branch (225:11): [True: 0, False: 0]
  ------------------
  226|      0|		case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (226:3): [True: 0, False: 0]
  ------------------
  227|      0|			if (card->ops->verify != NULL)
  ------------------
  |  Branch (227:8): [True: 0, False: 0]
  ------------------
  228|      0|				r = card->ops->verify(card,
  229|      0|					data->pin_type,
  230|      0|					data->pin_reference,
  231|      0|					data->pin1.data,
  232|      0|					(size_t) data->pin1.len,
  233|      0|					&data->pin1.tries_left);
  234|      0|			break;
  235|      0|		case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (235:3): [True: 0, False: 0]
  ------------------
  236|      0|			if (card->ops->change_reference_data != NULL)
  ------------------
  |  Branch (236:8): [True: 0, False: 0]
  ------------------
  237|      0|				r = card->ops->change_reference_data(card,
  238|      0|					data->pin_type,
  239|      0|					data->pin_reference,
  240|      0|					data->pin1.data,
  241|      0|					(size_t) data->pin1.len,
  242|      0|					data->pin2.data,
  243|      0|					(size_t) data->pin2.len,
  244|      0|					&data->pin1.tries_left);
  245|      0|			break;
  246|      0|		case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (246:3): [True: 0, False: 0]
  ------------------
  247|      0|			if (card->ops->reset_retry_counter != NULL)
  ------------------
  |  Branch (247:8): [True: 0, False: 0]
  ------------------
  248|      0|				r = card->ops->reset_retry_counter(card,
  249|      0|					data->pin_type,
  250|      0|					data->pin_reference,
  251|      0|					data->pin1.data,
  252|      0|					(size_t) data->pin1.len,
  253|      0|					data->pin2.data,
  254|      0|					(size_t) data->pin2.len);
  255|      0|			break;
  256|      0|		}
  257|      0|		if (r == SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (257:7): [True: 0, False: 0]
  ------------------
  258|      0|			sc_log(card->ctx,  "unsupported PIN operation (%d)",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  259|      0|					data->cmd);
  260|      0|	} else {
  261|      0|		sc_log(card->ctx,  "Use of pin pad not supported by card driver");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  262|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  263|      0|	}
  264|  10.8k|	card->ctx->debug = debug;
  265|       |
  266|  10.8k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  10.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  10.8k|	int _ret = r; \
  |  |  155|  10.8k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 10.8k, False: 0]
  |  |  ------------------
  |  |  156|  10.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|  7.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 7.01k, False: 3.87k]
  |  |  ------------------
  |  |  157|  10.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  10.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|  10.8k|	return _ret; \
  |  |  163|  10.8k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  267|  10.8k|}
sc_build_pin:
  281|  2.27k|{
  282|  2.27k|	size_t i = 0, j, pin_len = pin->len;
  283|       |
  284|  2.27k|	if (pin->max_length && pin_len > pin->max_length)
  ------------------
  |  Branch (284:6): [True: 2.00k, False: 267]
  |  Branch (284:25): [True: 0, False: 2.00k]
  ------------------
  285|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  286|       |
  287|  2.27k|	if (pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  434|  2.27k|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (287:6): [True: 46, False: 2.23k]
  ------------------
  288|    140|		while (pin_len > 0 && pin->data[pin_len - 1] == 0xFF)
  ------------------
  |  Branch (288:10): [True: 134, False: 6]
  |  Branch (288:25): [True: 94, False: 40]
  ------------------
  289|     94|			pin_len--;
  290|     46|		if (pin_len > 12)
  ------------------
  |  Branch (290:7): [True: 6, False: 40]
  ------------------
  291|      6|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      6|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  292|    114|		for (i = 0; i < pin_len; i++) {
  ------------------
  |  Branch (292:15): [True: 96, False: 18]
  ------------------
  293|     96|			if (pin->data[i] < '0' || pin->data[i] > '9')
  ------------------
  |  Branch (293:8): [True: 8, False: 88]
  |  Branch (293:30): [True: 14, False: 74]
  ------------------
  294|     22|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     22|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  295|     96|		}
  296|     18|		buf[0] = 0x20 | (u8) pin_len;
  297|     18|		buf++;
  298|     18|		buflen--;
  299|     18|	}
  300|       |
  301|       |	/* PIN given by application, encode if required */
  302|  2.24k|	if (pin->encoding == SC_PIN_ENCODING_ASCII) {
  ------------------
  |  |  432|  2.24k|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  |  Branch (302:6): [True: 2.20k, False: 45]
  ------------------
  303|  2.20k|		if (pin_len > buflen)
  ------------------
  |  Branch (303:7): [True: 26, False: 2.17k]
  ------------------
  304|     26|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     26|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  305|  2.17k|		memcpy(buf, pin->data, pin_len);
  306|  2.17k|		i = pin_len;
  307|  2.17k|	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  433|     90|#define SC_PIN_ENCODING_BCD	1
  ------------------
              	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  434|     18|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (307:13): [True: 27, False: 18]
  |  Branch (307:53): [True: 18, False: 0]
  ------------------
  308|     45|		if (pin_len > 2 * buflen)
  ------------------
  |  Branch (308:7): [True: 0, False: 45]
  ------------------
  309|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  310|    294|		for (i = j = 0; j < pin_len; j++) {
  ------------------
  |  Branch (310:19): [True: 263, False: 31]
  ------------------
  311|    263|			if (!isdigit(pin->data[j])) {
  ------------------
  |  Branch (311:8): [True: 14, False: 249]
  ------------------
  312|     14|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     14|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  313|     14|			}
  314|    249|			buf[i] <<= 4;
  315|    249|			buf[i] |= pin->data[j] & 0xf;
  316|    249|			if (j & 1)
  ------------------
  |  Branch (316:8): [True: 118, False: 131]
  ------------------
  317|    118|				i++;
  318|    249|		}
  319|     31|		if (j & 1) {
  ------------------
  |  Branch (319:7): [True: 10, False: 21]
  ------------------
  320|     10|			buf[i] <<= 4;
  321|     10|			buf[i] |= pin->pad_char & 0xf;
  322|     10|			i++;
  323|     10|		}
  324|     31|	}
  325|       |
  326|       |	/* Pad to maximum PIN length if requested */
  327|  2.20k|	if (pad || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  434|  1.01k|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (327:6): [True: 1.19k, False: 1.01k]
  |  Branch (327:13): [True: 0, False: 1.01k]
  ------------------
  328|  1.19k|		size_t pad_length = pin->pad_length;
  329|  1.19k|		u8     pad_char   = pin->encoding == SC_PIN_ENCODING_GLP ? 0xFF : pin->pad_char;
  ------------------
  |  |  434|  1.19k|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (329:23): [True: 18, False: 1.17k]
  ------------------
  330|       |
  331|  1.19k|		if (pin->encoding == SC_PIN_ENCODING_BCD)
  ------------------
  |  |  433|  1.19k|#define SC_PIN_ENCODING_BCD	1
  ------------------
  |  Branch (331:7): [True: 13, False: 1.17k]
  ------------------
  332|     13|			pad_length >>= 1;
  333|  1.19k|		if (pin->encoding == SC_PIN_ENCODING_GLP)
  ------------------
  |  |  434|  1.19k|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (333:7): [True: 18, False: 1.17k]
  ------------------
  334|     18|			pad_length = 8;
  335|       |
  336|  1.19k|		if (pad_length > buflen)
  ------------------
  |  Branch (336:7): [True: 0, False: 1.19k]
  ------------------
  337|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  338|       |
  339|  1.19k|		if (pad_length && i < pad_length) {
  ------------------
  |  Branch (339:7): [True: 1.03k, False: 155]
  |  Branch (339:21): [True: 416, False: 621]
  ------------------
  340|    416|			memset(buf + i, pad_char, pad_length - i);
  341|    416|			i = pad_length;
  342|    416|		}
  343|  1.19k|	}
  344|       |
  345|  2.20k|	return (int)i;
  346|  2.20k|}

sc_simpletlv_put_tag:
   43|    414|{
   44|    414|	u8 *p = out;
   45|       |
   46|    414|	if (outlen < 2 || (outlen < 4 && datalen >= 0xff))
  ------------------
  |  Branch (46:6): [True: 0, False: 414]
  |  Branch (46:21): [True: 34, False: 380]
  |  Branch (46:35): [True: 0, False: 34]
  ------------------
   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|    414|	if (tag == 0x00 || tag == 0xff)
  ------------------
  |  Branch (50:6): [True: 133, False: 281]
  |  Branch (50:21): [True: 41, False: 240]
  ------------------
   51|    174|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    174|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   52|    240|	if (datalen > 0xffff) {
  ------------------
  |  Branch (52:6): [True: 0, False: 240]
  ------------------
   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|    240|	*p++ = tag; /* tag is single byte */
   58|    240|	if (datalen < 0xff) {
  ------------------
  |  Branch (58:6): [True: 198, False: 42]
  ------------------
   59|       |		/* short value up to 255 */
   60|    198|		*p++ = (u8)datalen; /* is in the second byte */
   61|    198|	} else {
   62|       |		/* longer values up to 65535 */
   63|     42|		*p++ = (u8)0xff; /* first byte is 0xff */
   64|     42|		*p++ = (u8)datalen & 0xff;
   65|     42|		*p++ = (u8)(datalen >> 8) & 0xff; /* LE */
   66|     42|	}
   67|    240|	if (ptr != NULL)
  ------------------
  |  Branch (67:6): [True: 240, False: 0]
  ------------------
   68|    240|		*ptr = p;
   69|    240|	return SC_SUCCESS;
  ------------------
  |  |   28|    240|#define SC_SUCCESS				0
  ------------------
   70|    240|}
sc_simpletlv_read_tag:
   77|  57.5k|{
   78|  57.5k|	u8 tag;
   79|  57.5k|	size_t left = buflen, len;
   80|  57.5k|	const u8 *p = *buf;
   81|       |
   82|  57.5k|	*buf = NULL;
   83|       |
   84|  57.5k|	if (left < 2) {
  ------------------
  |  Branch (84:6): [True: 361, False: 57.2k]
  ------------------
   85|    361|		return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|    361|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
   86|    361|	}
   87|  57.2k|	tag = *p;
   88|  57.2k|	p++;
   89|  57.2k|	len = *p;
   90|  57.2k|	p++;
   91|  57.2k|	left -= 2;
   92|       |
   93|  57.2k|	if (len == 0xff) {
  ------------------
  |  Branch (93:6): [True: 1.32k, False: 55.8k]
  ------------------
   94|       |		/* don't crash on bad data */
   95|  1.32k|		if (left < 2) {
  ------------------
  |  Branch (95:7): [True: 95, False: 1.23k]
  ------------------
   96|     95|			return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|     95|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
   97|     95|		}
   98|       |		/* skip two bytes (the size) */
   99|  1.23k|		len = lebytes2ushort(p);
  100|  1.23k|		p += 2;
  101|  1.23k|		left -= 2;
  102|  1.23k|	}
  103|       |
  104|  57.1k|	*tag_out = tag;
  105|  57.1k|	*taglen = len;
  106|  57.1k|	*buf = p;
  107|       |
  108|  57.1k|	if (len > left)
  ------------------
  |  Branch (108:6): [True: 4.93k, False: 52.1k]
  ------------------
  109|  4.93k|		return SC_ERROR_TLV_END_OF_CONTENTS;
  ------------------
  |  |   99|  4.93k|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  110|       |
  111|  52.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  52.1k|#define SC_SUCCESS				0
  ------------------
  112|  57.1k|}

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

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

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

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

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

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

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

