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

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

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

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

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

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

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

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

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

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

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

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

sc_get_authentic_driver:
 2149|  14.1k|{
 2150|  14.1k|	return sc_get_driver();
 2151|  14.1k|}
card-authentic.c:sc_get_driver:
 2114|  14.1k|{
 2115|  14.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2116|       |
 2117|  14.1k|	if (!iso_ops)
  ------------------
  |  Branch (2117:6): [True: 1, False: 14.1k]
  ------------------
 2118|      1|		iso_ops = iso_drv->ops;
 2119|       |
 2120|  14.1k|	authentic_ops = *iso_ops;
 2121|       |
 2122|  14.1k|	authentic_ops.match_card = authentic_match_card;
 2123|  14.1k|	authentic_ops.init = authentic_init;
 2124|  14.1k|	authentic_ops.finish = authentic_finish;
 2125|  14.1k|	authentic_ops.read_binary = authentic_read_binary;
 2126|  14.1k|	authentic_ops.write_binary = authentic_write_binary;
 2127|  14.1k|	authentic_ops.update_binary = authentic_update_binary;
 2128|  14.1k|	authentic_ops.erase_binary = authentic_erase_binary;
 2129|       |	/* authentic_ops.resize_file = authentic_resize_file; */
 2130|  14.1k|	authentic_ops.select_file = authentic_select_file;
 2131|       |	/* get_response: Untested */
 2132|  14.1k|	authentic_ops.get_challenge = authentic_get_challenge;
 2133|  14.1k|	authentic_ops.set_security_env = authentic_set_security_env;
 2134|       |	/* decipher: Untested */
 2135|  14.1k|	authentic_ops.decipher = authentic_decipher;
 2136|       |	/* authentic_ops.compute_signature = authentic_compute_signature; */
 2137|  14.1k|	authentic_ops.create_file = authentic_create_file;
 2138|  14.1k|	authentic_ops.delete_file = authentic_delete_file;
 2139|  14.1k|	authentic_ops.card_ctl = authentic_card_ctl;
 2140|  14.1k|	authentic_ops.process_fci = authentic_process_fci;
 2141|  14.1k|	authentic_ops.pin_cmd = authentic_pin_cmd;
 2142|  14.1k|	authentic_ops.card_reader_lock_obtained = authentic_card_reader_lock_obtained;
 2143|       |
 2144|  14.1k|	return &authentic_drv;
 2145|  14.1k|}
card-authentic.c:authentic_match_card:
  390|  10.1k|{
  391|  10.1k|	struct sc_context *ctx = card->ctx;
  392|  10.1k|	int i;
  393|       |
  394|  10.1k|	sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
  ------------------
  |  |  129|  10.1k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  10.1k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|  10.1k|	i = _sc_match_atr(card, authentic_known_atrs, &card->type);
  396|  10.1k|	if (i < 0)   {
  ------------------
  |  Branch (396:6): [True: 9.87k, False: 246]
  ------------------
  397|  9.87k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  9.87k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  398|  9.87k|		return 0;
  399|  9.87k|	}
  400|       |
  401|    246|	sc_log(ctx, "'%s' card matched", authentic_known_atrs[i].name);
  ------------------
  |  |   71|    246|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  402|    246|	return 1;
  403|  10.1k|}
card-authentic.c:authentic_init:
  442|    246|{
  443|    246|	struct sc_context *ctx = card->ctx;
  444|    246|	int ii, rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|    246|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  445|       |
  446|    246|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    246|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    246|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    246|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    246|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 246]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  447|    246|	for(ii=0;authentic_known_atrs[ii].atr;ii++)   {
  ------------------
  |  Branch (447:11): [True: 246, False: 0]
  ------------------
  448|    246|		if (card->type == authentic_known_atrs[ii].type)   {
  ------------------
  |  Branch (448:7): [True: 246, False: 0]
  ------------------
  449|    246|			card->name = authentic_known_atrs[ii].name;
  450|    246|			card->flags = authentic_known_atrs[ii].flags;
  451|    246|			break;
  452|    246|		}
  453|    246|	}
  454|       |
  455|    246|	if (!authentic_known_atrs[ii].atr)
  ------------------
  |  Branch (455:6): [True: 0, False: 246]
  ------------------
  456|    246|		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|    246|	card->cla  = 0x00;
  459|    246|	card->drv_data = (struct authentic_private_data *) calloc(1, sizeof(struct authentic_private_data));
  460|    246|	if (!card->drv_data)
  ------------------
  |  Branch (460:6): [True: 0, False: 246]
  ------------------
  461|    246|		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|    246|	if (card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (463:6): [True: 246, False: 0]
  ------------------
  464|    246|		rv = authentic_init_oberthur_authentic_3_2(card);
  465|       |
  466|    246|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    246|#define SC_SUCCESS				0
  ------------------
  |  Branch (466:6): [True: 133, False: 113]
  ------------------
  467|    133|		rv = authentic_get_serialnr(card, NULL);
  468|       |
  469|    246|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    246|#define SC_SUCCESS				0
  ------------------
  |  Branch (469:6): [True: 22, False: 224]
  ------------------
  470|     22|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     22|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  471|       |
  472|       |	/* Free private data on error */
  473|    246|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    246|#define SC_SUCCESS				0
  ------------------
  |  Branch (473:6): [True: 22, False: 224]
  ------------------
  474|     22|		free(card->drv_data);
  475|     22|		card->drv_data = NULL;
  476|     22|	}
  477|    246|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    246|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    246|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    246|	int _ret = r; \
  |  |  |  |  155|    246|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 246, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    246|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 22, False: 224]
  |  |  |  |  ------------------
  |  |  |  |  157|    246|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    246|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    246|	return _ret; \
  |  |  |  |  163|    246|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  478|    246|}
card-authentic.c:authentic_init_oberthur_authentic_3_2:
  408|    246|{
  409|    246|	struct sc_context *ctx = card->ctx;
  410|    246|	unsigned int flags;
  411|    246|	int rv = 0;
  412|       |
  413|    246|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    246|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    246|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    246|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    246|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 246]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|       |
  415|    246|	flags = AUTHENTIC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   43|    246|#define AUTHENTIC_CARD_DEFAULT_FLAGS ( 0		\
  |  |   44|    246|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    246|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   45|    246|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    246|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   46|    246|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    246|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  109|    246|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  |  |  ------------------
  |  |  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|    246|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   47|    246|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    246|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   48|    246|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    246|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   49|    246|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    246|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  416|       |
  417|    246|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    246|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  418|    246|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    246|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  419|    246|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    246|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  420|       |
  421|    246|#ifdef ENABLE_SM
  422|    246|	card->sm_ctx.ops.open = authentic_sm_open;
  423|    246|	card->sm_ctx.ops.get_sm_apdu = authentic_sm_get_wrapped_apdu;
  424|    246|	card->sm_ctx.ops.free_sm_apdu = authentic_sm_free_wrapped_apdu;
  425|    246|#endif
  426|       |
  427|    246|	rv = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
  428|    246|	LOG_TEST_RET(ctx, rv, "AuthentIC application select error");
  ------------------
  |  |  174|    246|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    246|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    246|	int _ret = (r); \
  |  |  |  |  168|    246|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 122, False: 124]
  |  |  |  |  ------------------
  |  |  |  |  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|    246|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 124]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|       |
  430|    124|	rv = authentic_select_mf(card, NULL);
  431|    124|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    124|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    124|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    124|	int _ret = (r); \
  |  |  |  |  168|    124|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 113]
  |  |  |  |  ------------------
  |  |  |  |  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|    124|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 113]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|       |
  433|    113|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  434|    113|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  435|       |
  436|    113|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|    113|}
card-authentic.c:authentic_select_mf:
  544|    124|{
  545|    124|	struct sc_context *ctx = card->ctx;
  546|    124|	struct sc_path mfpath;
  547|    124|	int rv;
  548|       |
  549|    124|	struct sc_apdu apdu;
  550|    124|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  551|       |
  552|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  553|       |
  554|    124|	sc_format_path("3F00", &mfpath);
  555|    124|	mfpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    124|#define SC_PATH_TYPE_PATH		2
  ------------------
  556|       |
  557|    124|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  292|    124|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  558|       |
  559|    124|	apdu.resp = rbuf;
  560|    124|	apdu.resplen = sizeof(rbuf);
  561|       |
  562|    124|	rv = sc_transmit_apdu(card, &apdu);
  563|    124|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    124|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    124|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    124|	int _ret = (r); \
  |  |  |  |  168|    124|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  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|    124|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  564|    123|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  565|    123|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|    123|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    123|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    123|	int _ret = (r); \
  |  |  |  |  168|    123|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 121]
  |  |  |  |  ------------------
  |  |  |  |  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|    123|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 121]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|       |
  567|    121|	rv = authentic_set_current_files(card, &mfpath, apdu.resp, apdu.resplen, file_out);
  568|    121|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    121|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    121|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    121|	int _ret = (r); \
  |  |  |  |  168|    121|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 113]
  |  |  |  |  ------------------
  |  |  |  |  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|    121|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 113]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|       |
  570|    113|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|    113|}
card-authentic.c:authentic_set_current_files:
  505|    489|{
  506|    489|	struct sc_context *ctx = card->ctx;
  507|    489|	struct sc_file *file = NULL;
  508|    489|	int rv;
  509|       |
  510|    489|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    489|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    489|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    489|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    489|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 489]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|    489|	if (resplen)   {
  ------------------
  |  Branch (511:6): [True: 230, False: 259]
  ------------------
  512|    230|		switch (resp[0]) {
  513|     39|		case 0x62:
  ------------------
  |  Branch (513:3): [True: 39, False: 191]
  ------------------
  514|    207|		case 0x6F:
  ------------------
  |  Branch (514:3): [True: 168, False: 62]
  ------------------
  515|    207|			file = sc_file_new();
  516|    207|			if (file == NULL)
  ------------------
  |  Branch (516:8): [True: 0, False: 207]
  ------------------
  517|    207|				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|    207|			if (path)
  ------------------
  |  Branch (518:8): [True: 207, False: 0]
  ------------------
  519|    207|				file->path = *path;
  520|       |
  521|    207|			rv = authentic_process_fci(card, file, resp, resplen);
  522|    207|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    207|#define SC_SUCCESS				0
  ------------------
  |  Branch (522:8): [True: 26, False: 181]
  ------------------
  523|     26|				sc_file_free(file);
  524|     26|				LOG_TEST_RET(ctx, rv, "cannot set 'current file': FCI process error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  525|     26|			}
  526|       |
  527|    181|			break;
  528|    181|		default:
  ------------------
  |  Branch (528:3): [True: 23, False: 207]
  ------------------
  529|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  530|    230|		}
  531|       |
  532|    181|		if (file_out)
  ------------------
  |  Branch (532:7): [True: 84, False: 97]
  ------------------
  533|     84|			*file_out = file;
  534|     97|		else
  535|     97|			sc_file_free(file);
  536|    181|	}
  537|       |
  538|    440|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    440|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    440|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    440|	int _ret = r; \
  |  |  |  |  155|    440|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 440, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    440|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 440]
  |  |  |  |  ------------------
  |  |  |  |  157|    440|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    440|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    440|	return _ret; \
  |  |  |  |  163|    440|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|    440|}
card-authentic.c:authentic_get_serialnr:
 1464|    232|{
 1465|    232|	struct sc_context *ctx = card->ctx;
 1466|    232|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1467|    232|	int rv;
 1468|       |
 1469|    232|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    232|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    232|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    232|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    232|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 232]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1470|    232|	if (!card->serialnr.len)   {
  ------------------
  |  Branch (1470:6): [True: 148, False: 84]
  ------------------
 1471|    148|		rv = authentic_get_cplc(card);
 1472|    148|		LOG_TEST_RET(ctx, rv, "get CPLC data error");
  ------------------
  |  |  174|    148|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    148|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    148|	int _ret = (r); \
  |  |  |  |  168|    148|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 37, False: 111]
  |  |  |  |  ------------------
  |  |  |  |  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|    148|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 111]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1473|       |
 1474|    111|		card->serialnr.len = 4;
 1475|    111|		memcpy(card->serialnr.value, prv_data->cplc.value + 15, 4);
 1476|       |
 1477|    111|		sc_log(ctx, "serial %02X%02X%02X%02X",
  ------------------
  |  |   71|    111|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1478|    111|				card->serialnr.value[0], card->serialnr.value[1],
 1479|    111|				card->serialnr.value[2], card->serialnr.value[3]);
 1480|    111|	}
 1481|       |
 1482|    195|	if (serial)
  ------------------
  |  Branch (1482:6): [True: 84, False: 111]
  ------------------
 1483|     84|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1484|       |
 1485|    195|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    195|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    195|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    195|	int _ret = r; \
  |  |  |  |  155|    195|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 195, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    195|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 195]
  |  |  |  |  ------------------
  |  |  |  |  157|    195|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    195|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    195|	return _ret; \
  |  |  |  |  163|    195|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1486|    195|}
card-authentic.c:authentic_get_cplc:
  360|    148|{
  361|    148|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
  362|    148|	struct sc_apdu apdu;
  363|    148|	int rv, ii;
  364|    148|	unsigned char p1, p2;
  365|       |
  366|    148|	p1 = (SC_CPLC_TAG >> 8) & 0xFF;
  ------------------
  |  |  345|    148|#define SC_CPLC_TAG		0x9F7F
  ------------------
  367|    148|	p2 = SC_CPLC_TAG & 0xFF;
  ------------------
  |  |  345|    148|#define SC_CPLC_TAG		0x9F7F
  ------------------
  368|    148|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, p1, p2);
  ------------------
  |  |  292|    148|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  369|    151|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (369:12): [True: 150, False: 1]
  ------------------
  370|    150|		apdu.le = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    150|#define SC_CPLC_DER_SIZE	45
  ------------------
  371|    150|		apdu.resplen = sizeof(prv_data->cplc.value);
  372|    150|		apdu.resp = prv_data->cplc.value;
  373|       |
  374|    150|		rv = sc_transmit_apdu(card, &apdu);
  375|    150|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    150|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    150|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    150|	int _ret = (r); \
  |  |  |  |  168|    150|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 149]
  |  |  |  |  ------------------
  |  |  |  |  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|    150|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 149]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    149|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  377|    149|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    149|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (377:7): [True: 146, False: 3]
  ------------------
  378|    146|			break;
  379|       |
  380|      3|		apdu.cla = 0x80;
  381|      3|	}
  382|    147|        LOG_TEST_RET(card->ctx, rv, "'GET CPLC' error");
  ------------------
  |  |  174|    147|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    147|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    147|	int _ret = (r); \
  |  |  |  |  168|    147|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 36, False: 111]
  |  |  |  |  ------------------
  |  |  |  |  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|    147|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 111]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  383|       |
  384|    111|	prv_data->cplc.len = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    111|#define SC_CPLC_DER_SIZE	45
  ------------------
  385|    111|	return SC_SUCCESS;
  ------------------
  |  |   28|    111|#define SC_SUCCESS				0
  ------------------
  386|    147|}
card-authentic.c:authentic_finish:
 1847|    224|{
 1848|    224|	struct sc_context *ctx = card->ctx;
 1849|       |
 1850|    224|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    224|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    224|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    224|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    224|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 224]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1851|       |
 1852|    224|#ifdef ENABLE_SM
 1853|    224|	if (card->sm_ctx.ops.close)
  ------------------
  |  Branch (1853:6): [True: 0, False: 224]
  ------------------
 1854|      0|		card->sm_ctx.ops.close(card);
 1855|    224|#endif
 1856|       |
 1857|    224|	if (card->drv_data)
  ------------------
  |  Branch (1857:6): [True: 224, False: 0]
  ------------------
 1858|    224|		free(card->drv_data);
 1859|    224|	card->drv_data = NULL;
 1860|    224|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 224]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1861|    224|}
card-authentic.c:authentic_read_binary:
  643|    378|{
  644|    378|	struct sc_context *ctx = card->ctx;
  645|    378|	struct sc_apdu apdu;
  646|    378|	size_t sz, rest, ret_count = 0;
  647|    378|	int rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    378|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  648|       |
  649|    378|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    378|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    378|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    378|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    378|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 378]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  650|    378|	sc_log(ctx, "offs:%i,count:%zu,max_recv_size:%zu", idx, count, card->max_recv_size);
  ------------------
  |  |   71|    378|#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|       |
  652|    378|	rest = count;
  653|  1.24k|	while(rest)   {
  ------------------
  |  Branch (653:8): [True: 878, False: 371]
  ------------------
  654|    878|		sz = rest > 256 ? 256 : rest;
  ------------------
  |  Branch (654:8): [True: 501, False: 377]
  ------------------
  655|    878|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  292|    878|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  656|    878|		apdu.le = sz;
  657|    878|		apdu.resplen = sz;
  658|    878|		apdu.resp = (buf + ret_count);
  659|       |
  660|    878|		rv = sc_transmit_apdu(card, &apdu);
  661|    878|		if(!rv)
  ------------------
  |  Branch (661:6): [True: 871, False: 7]
  ------------------
  662|    871|			ret_count += apdu.resplen;
  663|      7|		else
  664|      7|			break;
  665|       |
  666|    871|		idx += sz;
  667|    871|		rest -= sz;
  668|    871|	}
  669|       |
  670|    378|	if (rv)   {
  ------------------
  |  Branch (670:6): [True: 7, False: 371]
  ------------------
  671|      7|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "authentic_read_binary() 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  673|      0|	}
  674|       |
  675|    371|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  676|    371|	if (!rv)
  ------------------
  |  Branch (676:6): [True: 339, False: 32]
  ------------------
  677|    339|		count = ret_count;
  678|       |
  679|    371|	LOG_TEST_RET(ctx, rv, "authentic_read_binary() failed");
  ------------------
  |  |  174|    371|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    371|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    371|	int _ret = (r); \
  |  |  |  |  168|    371|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 339]
  |  |  |  |  ------------------
  |  |  |  |  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|    371|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 339]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  680|    339|	LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  164|    339|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    339|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    339|	int _ret = r; \
  |  |  |  |  155|    339|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 332]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    332|	} else { \
  |  |  |  |  159|    332|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    332|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    332|	} \
  |  |  |  |  162|    339|	return _ret; \
  |  |  |  |  163|    339|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  681|    339|}
card-authentic.c:authentic_select_file:
  576|  1.23k|{
  577|  1.23k|	struct sc_context *ctx = card->ctx;
  578|  1.23k|	struct sc_apdu apdu;
  579|  1.23k|	struct sc_path lpath;
  580|  1.23k|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  581|  1.23k|	size_t pathlen;
  582|  1.23k|	int rv;
  583|       |
  584|  1.23k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.23k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.23k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.23k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.23k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|       |
  586|  1.23k|	memcpy(&lpath, path, sizeof(struct sc_path));
  587|       |
  588|  1.23k|	if (lpath.type == SC_PATH_TYPE_PATH && (lpath.len == 2))
  ------------------
  |  |  119|  2.47k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (588:6): [True: 699, False: 538]
  |  Branch (588:41): [True: 24, False: 675]
  ------------------
  589|     24|		lpath.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     24|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  590|       |
  591|  1.23k|	pathlen = lpath.len;
  592|  1.23k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.23k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  593|       |
  594|  1.23k|	if (card->type != SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (594:6): [True: 0, False: 1.23k]
  ------------------
  595|  1.23k|		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.23k|	if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  1.23k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (597:6): [True: 24, False: 1.21k]
  ------------------
  598|     24|		apdu.p1 = 0x00;
  599|     24|	}
  600|  1.21k|	else if (lpath.type == SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  1.21k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (600:11): [True: 675, False: 538]
  ------------------
  601|    675|		apdu.p1 = 0x08;
  602|    675|	}
  603|    538|	else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|    538|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (603:11): [True: 0, False: 538]
  ------------------
  604|      0|		apdu.p1 = 0x09;
  605|      0|	}
  606|    538|	else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|    538|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (606:11): [True: 538, False: 0]
  ------------------
  607|    538|		apdu.p1 = 4;
  608|    538|	}
  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.23k|	apdu.lc = pathlen;
  620|  1.23k|	apdu.data = lpath.value;
  621|  1.23k|	apdu.datalen = pathlen;
  622|       |
  623|  1.23k|	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  294|  2.47k|#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.23k, False: 0]
  |  Branch (623:42): [True: 0, False: 0]
  ------------------
  624|  1.23k|		apdu.resp = rbuf;
  625|  1.23k|		apdu.resplen = sizeof(rbuf);
  626|  1.23k|		apdu.le = 256;
  627|  1.23k|	}
  628|       |
  629|  1.23k|	rv = sc_transmit_apdu(card, &apdu);
  630|  1.23k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.23k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.23k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.23k|	int _ret = (r); \
  |  |  |  |  168|  1.23k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 1.22k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.22k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|  1.22k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  632|  1.22k|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|  1.22k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.22k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.22k|	int _ret = (r); \
  |  |  |  |  168|  1.22k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 858, False: 368]
  |  |  |  |  ------------------
  |  |  |  |  169|    858|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    858|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    858|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    858|		return _ret; \
  |  |  |  |  172|    858|	} \
  |  |  |  |  173|  1.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 368]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  633|       |
  634|    368|	rv = authentic_set_current_files(card, &lpath, apdu.resp, apdu.resplen, file_out);
  635|    368|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    368|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    368|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    368|	int _ret = (r); \
  |  |  |  |  168|    368|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 41, False: 327]
  |  |  |  |  ------------------
  |  |  |  |  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|    368|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 327]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|    327|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    327|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    327|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    327|	int _ret = r; \
  |  |  |  |  155|    327|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 327, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    327|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 327]
  |  |  |  |  ------------------
  |  |  |  |  157|    327|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    327|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    327|	return _ret; \
  |  |  |  |  163|    327|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|    327|}
card-authentic.c:authentic_card_ctl:
 1738|     99|{
 1739|     99|	struct sc_context *ctx = card->ctx;
 1740|     99|	struct sc_authentic_sdo *sdo = (struct sc_authentic_sdo *) ptr;
 1741|       |
 1742|     99|	switch (cmd) {
  ------------------
  |  Branch (1742:10): [True: 99, False: 0]
  ------------------
 1743|     99|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1743:2): [True: 99, False: 0]
  ------------------
 1744|     99|		return authentic_get_serialnr(card, (struct sc_serial_number *)ptr);
 1745|      0|	case SC_CARDCTL_AUTHENTIC_SDO_CREATE:
  ------------------
  |  Branch (1745:2): [True: 0, False: 99]
  ------------------
 1746|      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__
  |  |  ------------------
  ------------------
 1747|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1748|      0|	case SC_CARDCTL_AUTHENTIC_SDO_DELETE:
  ------------------
  |  Branch (1748:2): [True: 0, False: 99]
  ------------------
 1749|      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__
  |  |  ------------------
  ------------------
 1750|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1751|      0|	case SC_CARDCTL_AUTHENTIC_SDO_STORE:
  ------------------
  |  Branch (1751:2): [True: 0, False: 99]
  ------------------
 1752|      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__
  |  |  ------------------
  ------------------
 1753|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1754|      0|	case SC_CARDCTL_AUTHENTIC_SDO_GENERATE:
  ------------------
  |  Branch (1754:2): [True: 0, False: 99]
  ------------------
 1755|      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__
  |  |  ------------------
  ------------------
 1756|      0|		return authentic_manage_sdo_generate(card, (struct sc_authentic_sdo *) ptr);
 1757|     99|	}
 1758|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1759|     99|}
card-authentic.c:authentic_get_tagged_data:
  177|    134|{
  178|    134|	size_t size_len, tag_len, offs, size;
  179|    134|	int rv;
  180|    134|	unsigned tag;
  181|       |
  182|    134|	if (!out || !out_len)
  ------------------
  |  Branch (182:6): [True: 0, False: 134]
  |  Branch (182:14): [True: 0, False: 134]
  ------------------
  183|    134|		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|    932|	for (offs = 0; offs < in_len; )   {
  ------------------
  |  Branch (185:17): [True: 880, False: 52]
  ------------------
  186|    880|		if ((*(in + offs) == 0x7F) || (*(in + offs) == 0x5F))   {
  ------------------
  |  Branch (186:7): [True: 82, False: 798]
  |  Branch (186:33): [True: 88, False: 710]
  ------------------
  187|    170|			if (offs + 1 >= in_len)
  ------------------
  |  Branch (187:8): [True: 5, False: 165]
  ------------------
  188|    170|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|      5|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      5|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      5|	int _ret = (r); \
  |  |  |  |  168|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|    165|			tag = *(in + offs) * 0x100 + *(in + offs + 1);
  190|    165|			tag_len = 2;
  191|    165|		}
  192|    710|		else   {
  193|    710|			tag = *(in + offs);
  194|    710|			tag_len = 1;
  195|    710|		}
  196|       |
  197|    875|		if (offs + tag_len >= in_len)
  ------------------
  |  Branch (197:7): [True: 16, False: 859]
  ------------------
  198|    875|			LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|    859|		rv = authentic_parse_size(in + offs + tag_len, in_len - (offs + tag_len), &size);
  201|    859|		LOG_TEST_RET(ctx, rv, "parse error: invalid size data");
  ------------------
  |  |  174|    859|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    859|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    859|	int _ret = (r); \
  |  |  |  |  168|    859|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 849]
  |  |  |  |  ------------------
  |  |  |  |  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|    859|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 849]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|    849|		size_len = rv;
  203|       |
  204|    849|		if (tag == in_tag)   {
  ------------------
  |  Branch (204:7): [True: 51, False: 798]
  ------------------
  205|     51|			if (in_len - (offs + tag_len + size_len) < size)
  ------------------
  |  Branch (205:8): [True: 2, False: 49]
  ------------------
  206|     51|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|       |
  208|     49|			*out = in + offs + tag_len + size_len;
  209|     49|			*out_len = size;
  210|       |
  211|     49|			return SC_SUCCESS;
  ------------------
  |  |   28|     49|#define SC_SUCCESS				0
  ------------------
  212|     51|		}
  213|       |
  214|    798|		offs += tag_len + size_len + size;
  215|    798|	}
  216|       |
  217|     52|	return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|     52|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  218|    134|}
card-authentic.c:authentic_parse_size:
  149|    859|{
  150|    859|	if (!in || !out || in_len < 1)
  ------------------
  |  Branch (150:6): [True: 0, False: 859]
  |  Branch (150:13): [True: 0, False: 859]
  |  Branch (150:21): [True: 0, False: 859]
  ------------------
  151|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  152|       |
  153|    859|	if (*in < 0x80)   {
  ------------------
  |  Branch (153:6): [True: 693, False: 166]
  ------------------
  154|    693|		*out = *in;
  155|    693|		return 1;
  156|    693|	}
  157|    166|	else if (*in == 0x81)   {
  ------------------
  |  Branch (157:11): [True: 76, False: 90]
  ------------------
  158|     76|		if (in_len < 2)
  ------------------
  |  Branch (158:7): [True: 1, False: 75]
  ------------------
  159|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  160|     75|		*out = *(in + 1);
  161|     75|		return 2;
  162|     76|	}
  163|     90|	else if (*in == 0x82)   {
  ------------------
  |  Branch (163:11): [True: 82, False: 8]
  ------------------
  164|     82|		if (in_len < 3)
  ------------------
  |  Branch (164:7): [True: 1, False: 81]
  ------------------
  165|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  166|     81|		*out = *(in + 1) * 0x100 + *(in + 2);
  167|     81|		return 3;
  168|     82|	}
  169|       |
  170|      8|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      8|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  171|    859|}
card-authentic.c:authentic_process_fci:
  769|    207|{
  770|    207|	struct sc_context *ctx = card->ctx;
  771|    207|	size_t taglen;
  772|    207|	int rv;
  773|    207|	unsigned ii;
  774|    207|	const unsigned char *tag = NULL;
  775|    207|	unsigned char ops_DF[8] = {
  776|    207|		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  169|    207|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    207|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  173|    207|#define SC_AC_OP_CRYPTO			7
  ------------------
  777|    207|	};
  778|    207|	unsigned char ops_EF[8] = {
  779|    207|		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  188|    207|#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|    207|#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|    207|#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|    207|#define SC_AC_OP_RESIZE			25
  ------------------
  780|    207|	};
  781|       |
  782|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  783|       |
  784|    207|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x6F, &taglen);
  785|    207|	if (tag != NULL) {
  ------------------
  |  Branch (785:6): [True: 160, False: 47]
  ------------------
  786|    160|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|    160|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  787|    160|		buf = tag;
  788|    160|		buflen = taglen;
  789|    160|	}
  790|       |
  791|    207|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x62, &taglen);
  792|    207|	if (tag != NULL) {
  ------------------
  |  Branch (792:6): [True: 38, False: 169]
  ------------------
  793|     38|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  794|     38|		buf = tag;
  795|     38|		buflen = taglen;
  796|     38|	}
  797|       |
  798|    207|	rv = iso_ops->process_fci(card, file, buf, buflen);
  799|    207|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    207|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    207|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    207|	int _ret = (r); \
  |  |  |  |  168|    207|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 207]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 207]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  800|       |
  801|    207|	if (!file->sec_attr_len)   {
  ------------------
  |  Branch (801:6): [True: 73, False: 134]
  ------------------
  802|     73|		sc_log_hex(ctx, "ACLs not found in data", buf, buflen);
  ------------------
  |  |  129|     73|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     73|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  803|     73|		sc_log(ctx, "Path:%s; Type:%X; PathType:%X", sc_print_path(&file->path), file->type, file->path.type);
  ------------------
  |  |   71|     73|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  804|     73|		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  118|    146|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|     51|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (804:7): [True: 22, False: 51]
  |  Branch (804:50): [True: 25, False: 26]
  ------------------
  805|     47|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     47|#define SC_FILE_TYPE_DF			0x04
  ------------------
  806|     47|		}
  807|     26|		else   {
  808|     26|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|     26|		}
  810|     73|	}
  811|       |
  812|    181|	sc_log_hex(ctx, "ACL data", file->sec_attr, file->sec_attr_len);
  ------------------
  |  |  129|    181|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    181|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  813|    642|	for (ii = 0; ii < file->sec_attr_len / 2 && ii < sizeof ops_DF; ii++)  {
  ------------------
  |  Branch (813:15): [True: 464, False: 178]
  |  Branch (813:46): [True: 461, False: 3]
  ------------------
  814|    461|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|    461|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (814:22): [True: 67, False: 394]
  ------------------
  815|    461|		unsigned char acl = *(file->sec_attr + ii*2);
  816|    461|		unsigned char cred_id = *(file->sec_attr + ii*2 + 1);
  817|    461|		unsigned sc = acl * 0x100 + cred_id;
  818|       |
  819|    461|		sc_log(ctx, "ACL(%i) op 0x%X, acl %X:%X", ii, op, acl, cred_id);
  ------------------
  |  |   71|    461|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  820|    461|		if (op == 0xFF)
  ------------------
  |  Branch (820:7): [True: 55, False: 406]
  ------------------
  821|     55|			;
  822|    406|		else if (!acl && !cred_id)
  ------------------
  |  Branch (822:12): [True: 113, False: 293]
  |  Branch (822:20): [True: 47, False: 66]
  ------------------
  823|     47|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|     47|#define SC_AC_NONE			0x00000000
  ------------------
  824|    359|		else if (acl == 0xFF)
  ------------------
  |  Branch (824:12): [True: 54, False: 305]
  ------------------
  825|     54|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     54|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  826|    305|		else if (acl & AUTHENTIC_AC_SM_MASK)
  ------------------
  |  |  119|    305|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (826:12): [True: 139, False: 166]
  ------------------
  827|    139|			sc_file_add_acl_entry(file, op, SC_AC_SCB, sc);
  ------------------
  |  |  157|    139|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  828|    166|		else if (cred_id)
  ------------------
  |  Branch (828:12): [True: 112, False: 54]
  ------------------
  829|    112|			sc_file_add_acl_entry(file, op, SC_AC_CHV, cred_id);
  ------------------
  |  |  151|    112|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  830|     54|		else
  831|     54|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     54|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  832|    461|	}
  833|       |
  834|    181|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    181|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    181|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    181|	int _ret = r; \
  |  |  |  |  155|    181|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 181, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    181|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 181]
  |  |  |  |  ------------------
  |  |  |  |  157|    181|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    181|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    181|	return _ret; \
  |  |  |  |  163|    181|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  835|    181|}
card-authentic.c:authentic_pin_cmd:
 1432|    102|{
 1433|    102|	struct sc_context *ctx = card->ctx;
 1434|    102|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    102|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1435|       |
 1436|    102|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1437|    102|	sc_log(ctx, "PIN-CMD:%X,PIN(type:%X,ret:%i)", data->cmd, data->pin_type, data->pin_reference);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1438|    102|	sc_log(ctx, "PIN1(%p,len:%zu,tries-left:%i)", data->pin1.data, data->pin1.len, data->pin1.tries_left);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1439|    102|	sc_log(ctx, "PIN2(%p,len:%zu)", data->pin2.data, data->pin2.len);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1440|       |
 1441|    102|	switch (data->cmd)   {
 1442|      3|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      3|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1442:2): [True: 3, False: 99]
  ------------------
 1443|      3|		rv = authentic_pin_verify(card, data);
 1444|      3|		break;
 1445|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1445:2): [True: 0, False: 102]
  ------------------
 1446|      0|		rv = authentic_pin_change(card, data);
 1447|      0|		break;
 1448|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1448:2): [True: 0, False: 102]
  ------------------
 1449|      0|		rv = authentic_pin_reset(card, data);
 1450|      0|		break;
 1451|     99|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|     99|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1451:2): [True: 99, False: 3]
  ------------------
 1452|     99|		rv = authentic_pin_get_policy(card, data, NULL);
 1453|     99|		break;
 1454|      0|	default:
  ------------------
  |  Branch (1454:2): [True: 0, False: 102]
  ------------------
 1455|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1456|    102|	}
 1457|       |
 1458|    102|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|     96|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 96, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1459|    102|}
card-authentic.c:authentic_pin_verify:
 1097|      3|{
 1098|      3|	struct sc_context *ctx = card->ctx;
 1099|      3|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1100|      3|	unsigned char pin_sha1[SHA_DIGEST_LENGTH];
 1101|      3|	int rv;
 1102|       |
 1103|      3|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|      3|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      3|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      3|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      3|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1104|      3|	sc_log(ctx, "PIN(type:%X,reference:%X,data:%p,length:%zu)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1105|      3|			pin_cmd->pin_type, pin_cmd->pin_reference, pin_cmd->pin1.data, pin_cmd->pin1.len);
 1106|       |
 1107|      3|	if (pin_cmd->pin_reference < 0 || pin_cmd->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|      3|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1107:6): [True: 0, False: 3]
  |  Branch (1107:36): [True: 0, False: 3]
  ------------------
 1108|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1109|      0|	}
 1110|       |
 1111|      3|	if (pin_cmd->pin1.data && !pin_cmd->pin1.len)   {
  ------------------
  |  Branch (1111:6): [True: 3, False: 0]
  |  Branch (1111:28): [True: 0, False: 3]
  ------------------
 1112|      0|		pin_cmd->pin1.tries_left = -1;
 1113|      0|		rv = authentic_pin_is_verified(card, pin_cmd);
 1114|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1115|      0|	}
 1116|       |
 1117|      3|	if (pin_cmd->pin1.data)
  ------------------
  |  Branch (1117:6): [True: 3, False: 0]
  ------------------
 1118|      3|		SHA1(pin_cmd->pin1.data, pin_cmd->pin1.len, pin_sha1);
 1119|      0|	else
 1120|      0|		SHA1((unsigned char *)"", 0, pin_sha1);
 1121|       |
 1122|      3|	if (!memcmp(pin_sha1, prv_data->pins_sha1[pin_cmd->pin_reference], SHA_DIGEST_LENGTH))   {
  ------------------
  |  Branch (1122:6): [True: 0, False: 3]
  ------------------
 1123|      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__
  |  |  ------------------
  ------------------
 1124|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1125|      0|	}
 1126|       |
 1127|      3|	memset(prv_data->pins_sha1[pin_cmd->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1128|       |
 1129|      3|	rv = authentic_pin_get_policy(card, pin_cmd, NULL);
 1130|      3|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' error");
  ------------------
  |  |  174|      3|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      3|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      3|	int _ret = (r); \
  |  |  |  |  168|      3|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|       |
 1132|      0|	if (pin_cmd->pin1.len > pin_cmd->pin1.max_length)
  ------------------
  |  Branch (1132:6): [True: 0, False: 0]
  ------------------
 1133|      0|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1134|       |
 1135|      0|	pin_cmd->pin1.tries_left = -1;
 1136|      0|	rv = authentic_chv_verify(card, pin_cmd);
 1137|      0|	LOG_TEST_RET(ctx, rv, "PIN CHV verification 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1138|       |
 1139|      0|	memcpy(prv_data->pins_sha1[pin_cmd->pin_reference], pin_sha1, SHA_DIGEST_LENGTH);
 1140|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1141|      0|}
card-authentic.c:authentic_pin_get_policy:
 1293|    102|{
 1294|    102|	struct sc_context *ctx = card->ctx;
 1295|    102|	struct sc_apdu apdu;
 1296|    102|	unsigned char rbuf[0x100];
 1297|    102|	int ii, rv;
 1298|       |
 1299|    102|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1300|    102|	sc_log(ctx, "get PIN(type:%X,ref:%X,tries-left:%i)", data->pin_type, data->pin_reference, data->pin1.tries_left);
  ------------------
  |  |   71|    102|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1301|       |
 1302|    102|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x5F, data->pin_reference);
  ------------------
  |  |  292|    102|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1303|    105|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (1303:12): [True: 104, False: 1]
  ------------------
 1304|    104|		apdu.le = sizeof(rbuf);
 1305|    104|		apdu.resp = rbuf;
 1306|    104|		apdu.resplen = sizeof(rbuf);
 1307|       |
 1308|    104|		rv = sc_transmit_apdu(card, &apdu);
 1309|    104|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    104|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    104|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    104|	int _ret = (r); \
  |  |  |  |  168|    104|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 103]
  |  |  |  |  ------------------
  |  |  |  |  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|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 103]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1310|    103|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1311|       |
 1312|    103|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    103|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (1312:7): [True: 100, False: 3]
  ------------------
 1313|    100|			break;
 1314|       |
 1315|      3|		apdu.cla = 0x80;
 1316|      3|	}
 1317|    101|        LOG_TEST_RET(ctx, rv, "'GET DATA' error");
  ------------------
  |  |  174|    101|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    101|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    101|	int _ret = (r); \
  |  |  |  |  168|    101|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 89]
  |  |  |  |  ------------------
  |  |  |  |  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|    101|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 89]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1318|       |
 1319|     89|	data->pin1.tries_left = -1;
 1320|       |
 1321|     89|	rv = authentic_parse_credential_data(ctx, data, acls, apdu.resp, apdu.resplen);
 1322|     89|        LOG_TEST_RET(ctx, rv, "Cannot parse credential data");
  ------------------
  |  |  174|     89|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     89|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     89|	int _ret = (r); \
  |  |  |  |  168|     89|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 83, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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|     89|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1323|       |
 1324|      6|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      6|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1325|      6|	data->pin1.offset = 5;
 1326|      6|	data->pin1.pad_char = 0xFF;
 1327|      6|	data->pin1.pad_length = data->pin1.max_length;
 1328|      6|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      6|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1329|       |
 1330|      6|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|      6|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1331|       |
 1332|      6|	sc_log(ctx, "PIN policy: size max/min/pad %zu/%zu/%zu, tries max/left %i/%i",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1333|      6|			data->pin1.max_length, data->pin1.min_length, data->pin1.pad_length,
 1334|      6|			data->pin1.max_tries, data->pin1.tries_left);
 1335|       |
 1336|      6|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1337|      6|}
card-authentic.c:authentic_parse_credential_data:
  286|     89|{
  287|     89|	unsigned char *data;
  288|     89|	size_t data_len;
  289|     89|	int rv, ii;
  290|     89|	unsigned tag = AUTHENTIC_TAG_CREDENTIAL | pin_cmd->pin_reference;
  ------------------
  |  |   94|     89|#define AUTHENTIC_TAG_CREDENTIAL			0x5F00
  ------------------
  291|       |
  292|     89|	rv = authentic_get_tagged_data(ctx, blob, blob_len, tag, &blob, &blob_len);
  293|     89|	LOG_TEST_RET(ctx, rv, "cannot get credential data");
  ------------------
  |  |  174|     89|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     89|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     89|	int _ret = (r); \
  |  |  |  |  168|     89|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 70, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  169|     70|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     70|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     70|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     70|		return _ret; \
  |  |  |  |  172|     70|	} \
  |  |  |  |  173|     89|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|       |
  295|     19|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT, &data, &data_len);
  ------------------
  |  |   95|     19|#define AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT		0x91
  ------------------
  296|     19|	LOG_TEST_RET(ctx, rv, "cannot get try limit");
  ------------------
  |  |  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: 4, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  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|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|     15|	pin_cmd->pin1.max_tries = *data;
  298|       |
  299|     15|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_MECH, &data, &data_len);
  ------------------
  |  |   73|     15|#define AUTHENTIC_TAG_DOCP_MECH			0x80
  ------------------
  300|     15|	LOG_TEST_RET(ctx, rv, "cannot get PIN type");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|     12|	if (data_len > 0 && *data == 0)
  ------------------
  |  Branch (301:6): [True: 11, False: 1]
  |  Branch (301:22): [True: 5, False: 6]
  ------------------
  302|      5|		pin_cmd->pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      5|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  303|      7|	else if (data_len > 0 && *data >= 2 && *data <= 7)
  ------------------
  |  Branch (303:11): [True: 6, False: 1]
  |  Branch (303:27): [True: 5, False: 1]
  |  Branch (303:41): [True: 3, False: 2]
  ------------------
  304|      3|		pin_cmd->pin_type = SC_AC_AUT;
  ------------------
  |  |  154|      3|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  305|      4|	else
  306|      4|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported Credential type");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Parse optional ACLs when requested */
  309|      8|	if (acls) {
  ------------------
  |  Branch (309:6): [True: 0, False: 8]
  ------------------
  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:%zu", data_len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  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|      8|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY, &data, &data_len);
  ------------------
  |  |   96|      8|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY		0xA1
  ------------------
  341|      8|	if (!rv)   {
  ------------------
  |  Branch (341:6): [True: 2, False: 6]
  ------------------
  342|      2|		blob = data;
  343|      2|		blob_len = data_len;
  344|       |
  345|      2|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH, &data, &data_len);
  ------------------
  |  |   97|      2|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH	0x83
  ------------------
  346|      2|		LOG_TEST_RET(ctx, rv, "failed to get PIN max.length value");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|      1|		pin_cmd->pin1.max_length = *data;
  348|       |
  349|      1|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH, &data, &data_len);
  ------------------
  |  |   98|      1|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH	0x84
  ------------------
  350|      1|		LOG_TEST_RET(ctx, rv, "failed to get PIN min.length value");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      0|		pin_cmd->pin1.min_length = *data;
  352|      0|	}
  353|       |
  354|      6|	return SC_SUCCESS;
  ------------------
  |  |   28|      6|#define SC_SUCCESS				0
  ------------------
  355|      8|}
card-authentic.c:authentic_card_reader_lock_obtained:
 1865|    732|{
 1866|    732|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    732|#define SC_SUCCESS				0
  ------------------
 1867|       |
 1868|    732|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    732|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    732|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    732|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 732]
  |  |  ------------------
  ------------------
 1869|       |
 1870|    732|	if (was_reset > 0
  ------------------
  |  Branch (1870:6): [True: 0, False: 732]
  ------------------
 1871|      0|			&& card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2) {
  ------------------
  |  Branch (1871:7): [True: 0, False: 0]
  ------------------
 1872|      0|		r = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
 1873|      0|	}
 1874|       |
 1875|    732|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    732|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    732|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    732|	int _ret = r; \
  |  |  |  |  155|    732|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 732, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    732|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 732]
  |  |  |  |  ------------------
  |  |  |  |  157|    732|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    732|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    732|	return _ret; \
  |  |  |  |  163|    732|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1876|    732|}

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

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

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

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

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

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

coolkey_get_attribute_data:
  602|  1.36k|{
  603|       |	/* handle the V0 objects first */
  604|  1.36k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  1.36k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (604:6): [True: 709, False: 654]
  ------------------
  605|    709|		return coolkey_v0_get_attribute_data(attr, buf_len, attr_out);
  606|    709|	}
  607|       |
  608|       |	/* don't crash if we encounter some new or corrupted coolkey device */
  609|    654|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|    654|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (609:6): [True: 0, False: 654]
  ------------------
  610|      0|		return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  611|      0|	}
  612|       |
  613|    654|	return coolkey_v1_get_attribute_data(attr, buf_len, attr_out);
  614|       |
  615|    654|}
coolkey_compare_id:
  757|  74.3k|{
  758|  74.3k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (758:6): [True: 0, False: 74.3k]
  |  Branch (758:19): [True: 0, False: 74.3k]
  ------------------
  759|      0|		return 1;
  760|  74.3k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  761|  74.3k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  762|  74.3k|}
coolkey_list_meter:
  765|  4.25k|size_t coolkey_list_meter(const void *el) {
  766|  4.25k|	return sizeof(sc_cardctl_coolkey_object_t);
  767|  4.25k|}
coolkey_fill_object:
 1364|  19.2k|{
 1365|  19.2k|	int r;
 1366|  19.2k|	size_t buf_len = obj->length;
 1367|  19.2k|	u8 *new_obj_data = NULL;
 1368|  19.2k|	sc_cardctl_coolkey_object_t *obj_entry;
 1369|  19.2k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  19.2k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1370|       |
 1371|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1372|       |
 1373|  19.2k|	if (obj->data != NULL) {
  ------------------
  |  Branch (1373:6): [True: 0, False: 19.2k]
  ------------------
 1374|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1375|      0|	}
 1376|  19.2k|	new_obj_data = malloc(buf_len);
 1377|  19.2k|	if (new_obj_data == NULL) {
  ------------------
  |  Branch (1377:6): [True: 0, False: 19.2k]
  ------------------
 1378|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1379|      0|	}
 1380|  19.2k|	r = coolkey_read_object(card, obj->id, 0, new_obj_data, buf_len,
 1381|  19.2k|				priv->nonce, sizeof(priv->nonce));
 1382|  19.2k|	if (r != (int)buf_len) {
  ------------------
  |  Branch (1382:6): [True: 17.5k, False: 1.73k]
  ------------------
 1383|  17.5k|		free(new_obj_data);
 1384|  17.5k|		if (r < 0) {
  ------------------
  |  Branch (1384:7): [True: 17.5k, False: 0]
  ------------------
 1385|  17.5k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  17.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.5k|	int _ret = r; \
  |  |  |  |  155|  17.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  17.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.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|  17.5k|	return _ret; \
  |  |  |  |  163|  17.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1386|  17.5k|		}
 1387|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1388|      0|	}
 1389|  1.73k|	obj_entry = coolkey_find_object_by_id(&priv->objects_list, obj->id);
 1390|  1.73k|	if (obj_entry == NULL) {
  ------------------
  |  Branch (1390:6): [True: 0, False: 1.73k]
  ------------------
 1391|      0|		free(new_obj_data);
 1392|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1393|      0|	}
 1394|  1.73k|	if (obj_entry->data != NULL) {
  ------------------
  |  Branch (1394:6): [True: 0, False: 1.73k]
  ------------------
 1395|      0|		free(new_obj_data);
 1396|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1397|      0|	}
 1398|       |	/* Make sure we will not go over the allocated limits in the other
 1399|       |	 * objects if they somehow got different lengths in matching objects */
 1400|  1.73k|	if (obj_entry->length != obj->length) {
  ------------------
  |  Branch (1400:6): [True: 0, False: 1.73k]
  ------------------
 1401|      0|		free(new_obj_data);
 1402|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1403|      0|	}
 1404|  1.73k|	obj_entry->data = new_obj_data;
 1405|  1.73k|	obj->data = new_obj_data;
 1406|  1.73k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.73k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1407|  1.73k|}
coolkey_find_object_by_template:
 1496|  1.09k|{
 1497|  1.09k|	list_t *list;
 1498|  1.09k|	sc_cardctl_coolkey_object_t *current, *rv = NULL;
 1499|  1.09k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.09k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1500|  1.09k|	int i, r;
 1501|  1.09k|	unsigned int tmp_pos = (unsigned int) -1;
 1502|       |
 1503|  1.09k|	list = &priv->objects_list;
 1504|  1.09k|	if (list->iter_active) {
  ------------------
  |  Branch (1504:6): [True: 1.09k, False: 0]
  ------------------
 1505|       |		/* workaround missing functionality of second iterator */
 1506|  1.09k|		tmp_pos = list->iter_pos;
 1507|  1.09k|		list_iterator_stop(list);
 1508|  1.09k|	}
 1509|       |
 1510|  1.09k|	list_iterator_start(list);
 1511|  18.7k|	while (list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1511:9): [True: 18.0k, False: 660]
  ------------------
 1512|  18.0k|		sc_cardctl_coolkey_attribute_t attribute;
 1513|  18.0k|		current = list_iterator_next(list);
 1514|  18.0k|		attribute.object = current;
 1515|       |
 1516|  19.3k|		for (i=0; i < count; i++) {
  ------------------
  |  Branch (1516:13): [True: 18.8k, False: 436]
  ------------------
 1517|  18.8k|			attribute.attribute_type = template[i].attribute_type;
 1518|  18.8k|			r = coolkey_find_attribute(card, &attribute);
 1519|  18.8k|			if (r < 0) {
  ------------------
  |  Branch (1519:8): [True: 10.8k, False: 8.08k]
  ------------------
 1520|  10.8k|				break;
 1521|  10.8k|			}
 1522|  8.08k|			if (template[i].attribute_data_type != attribute.attribute_data_type) {
  ------------------
  |  Branch (1522:8): [True: 115, False: 7.97k]
  ------------------
 1523|    115|				break;
 1524|    115|			}
 1525|  7.97k|			if (template[i].attribute_length != attribute.attribute_length) {
  ------------------
  |  Branch (1525:8): [True: 36, False: 7.93k]
  ------------------
 1526|     36|				break;
 1527|     36|			}
 1528|  7.93k|			if (memcmp(attribute.attribute_value, template[i].attribute_value,
  ------------------
  |  Branch (1528:8): [True: 6.68k, False: 1.24k]
  ------------------
 1529|  7.93k|							attribute.attribute_length) != 0) {
 1530|  6.68k|				break;
 1531|  6.68k|			}
 1532|  7.93k|		}
 1533|       |		/* just return the first one */
 1534|  18.0k|		if (i == count) {
  ------------------
  |  Branch (1534:7): [True: 436, False: 17.6k]
  ------------------
 1535|    436|			rv = current;
 1536|    436|			break;
 1537|    436|		}
 1538|  18.0k|	}
 1539|       |
 1540|  1.09k|	list_iterator_stop(list);
 1541|  1.09k|	if (tmp_pos != (unsigned int)-1) {
  ------------------
  |  Branch (1541:6): [True: 1.09k, False: 0]
  ------------------
 1542|       |		/* workaround missing functionality of second iterator */
 1543|  1.09k|		list_iterator_start(list);
 1544|  12.8k|		while (list_iterator_hasnext(list) && list->iter_pos < tmp_pos)
  ------------------
  |  Branch (1544:10): [True: 12.7k, False: 130]
  |  Branch (1544:41): [True: 11.7k, False: 966]
  ------------------
 1545|  11.7k|			(void) list_iterator_next(list);
 1546|  1.09k|	}
 1547|  1.09k|	return rv;
 1548|  1.09k|}
sc_get_coolkey_driver:
 2467|  14.1k|{
 2468|  14.1k|	return sc_get_driver();
 2469|  14.1k|}
card-coolkey.c:coolkey_v0_get_attribute_data:
  517|    709|{
  518|       |	/* we need to manually detect types CK_ULONG */
  519|    709|	CK_ATTRIBUTE_TYPE attr_type = coolkey_get_attribute_type(attr, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|    709|#define COOLKEY_V0_OBJECT 0
  ------------------
  520|    709|	int r;
  521|    709|	size_t len;
  522|       |
  523|    709|	attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1061|    709|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
  524|    709|	attr_out->attribute_length = 0;
  525|    709|	attr_out->attribute_value = NULL;
  526|       |
  527|    709|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  528|    709|	if (r < 0) {
  ------------------
  |  Branch (528:6): [True: 0, False: 709]
  ------------------
  529|      0|		return r;
  530|      0|	}
  531|    709|	if (len + sizeof(coolkey_v0_attribute_header_t) > buf_len) {
  ------------------
  |  Branch (531:6): [True: 108, False: 601]
  ------------------
  532|    108|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    108|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  533|    108|	}
  534|    601|	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  137|    601|#define CKA_CLASS 0x00000000UL
  ------------------
              	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  145|     15|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (534:6): [True: 586, False: 15]
  |  Branch (534:34): [True: 0, False: 15]
  ------------------
  535|    587|									 || (attr_type == CKA_KEY_TYPE)) {
  ------------------
  |  |  159|     15|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (535:14): [True: 1, False: 14]
  ------------------
  536|    587|		if (len != 4) {
  ------------------
  |  Branch (536:7): [True: 192, False: 395]
  ------------------
  537|    192|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    192|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  538|    192|		}
  539|    395|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1062|    395|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  540|    395|	}
  541|       |	/* return the length and the data */
  542|    409|	attr_out->attribute_length = len;
  543|    409|	attr_out->attribute_value = attr + sizeof(coolkey_v0_attribute_header_t);
  544|    409|	return SC_SUCCESS;
  ------------------
  |  |   28|    409|#define SC_SUCCESS				0
  ------------------
  545|    601|}
card-coolkey.c:coolkey_get_attribute_type:
  410|  12.6k|{
  411|  12.6k|	coolkey_attribute_header_t *attribute_header = (coolkey_attribute_header_t *) attr;
  412|       |
  413|  12.6k|	return bebytes2ulong(attribute_header->attribute_attr_type);
  414|  12.6k|}
card-coolkey.c:coolkey_v0_get_attribute_len:
  350|  7.18k|{
  351|  7.18k|	coolkey_v0_attribute_header_t *attribute_head = (coolkey_v0_attribute_header_t *)attr;
  352|       |	/* don't reference beyond our buffer */
  353|  7.18k|	if (buf_len < sizeof(coolkey_v0_attribute_header_t)) {
  ------------------
  |  Branch (353:6): [True: 364, False: 6.82k]
  ------------------
  354|    364|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    364|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  355|    364|	}
  356|  6.82k|	*len = bebytes2ushort(attribute_head->attribute_data_len);
  357|  6.82k|	return SC_SUCCESS;
  ------------------
  |  |   28|  6.82k|#define SC_SUCCESS				0
  ------------------
  358|  7.18k|}
card-coolkey.c:coolkey_v1_get_attribute_data:
  552|    654|{
  553|    654|	int r;
  554|    654|	size_t len;
  555|    654|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  556|       |
  557|    654|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (557:6): [True: 36, False: 618]
  ------------------
  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|    618|	switch (attribute_head->attribute_data_type) {
  563|       |	/* ULONG has implied length of 4 */
  564|    241|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|    241|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (564:2): [True: 241, False: 377]
  ------------------
  565|    241|		if (buf_len < (sizeof(coolkey_attribute_header_t) + 4)) {
  ------------------
  |  Branch (565:7): [True: 18, False: 223]
  ------------------
  566|     18|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     18|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  567|     18|		}
  568|    223|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1062|    223|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  569|    223|		attr_out->attribute_length = 4;
  570|    223|		attr_out->attribute_value = attr + sizeof(coolkey_attribute_header_t);
  571|    223|		return SC_SUCCESS;
  ------------------
  |  |   28|    223|#define SC_SUCCESS				0
  ------------------
  572|       |	/* BOOL_FALSE and BOOL_TRUE have implied length and data */
  573|       |	/* return type STRING for BOOLS */
  574|     38|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|     38|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (574:2): [True: 38, False: 580]
  ------------------
  575|     38|		attr_out->attribute_length = 1;
  576|     38|		attr_out->attribute_value =  &coolkey_static_false;
  577|     38|		return SC_SUCCESS;
  ------------------
  |  |   28|     38|#define SC_SUCCESS				0
  ------------------
  578|     36|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|     36|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (578:2): [True: 36, False: 582]
  ------------------
  579|     36|		attr_out->attribute_length = 1;
  580|     36|		attr_out->attribute_value =  &coolkey_static_true;
  581|     36|		return SC_SUCCESS;
  ------------------
  |  |   28|     36|#define SC_SUCCESS				0
  ------------------
  582|       |	/* string type has encoded length */
  583|    280|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|    280|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (583:2): [True: 280, False: 338]
  ------------------
  584|    280|		r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 0);
  585|    280|		if (r < SC_SUCCESS) {
  ------------------
  |  |   28|    280|#define SC_SUCCESS				0
  ------------------
  |  Branch (585:7): [True: 18, False: 262]
  ------------------
  586|     18|			return r;
  587|     18|		}
  588|    262|		if (buf_len < (len + sizeof(coolkey_attribute_header_t) + 2)) {
  ------------------
  |  Branch (588:7): [True: 49, False: 213]
  ------------------
  589|     49|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     49|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  590|     49|		}
  591|    213|		attr_out->attribute_value = attr+sizeof(coolkey_attribute_header_t)+2;
  592|    213|		attr_out->attribute_length = len;
  593|    213|		return SC_SUCCESS;
  ------------------
  |  |   28|    213|#define SC_SUCCESS				0
  ------------------
  594|     23|	default:
  ------------------
  |  Branch (594:2): [True: 23, False: 595]
  ------------------
  595|     23|		break;
  596|    618|	}
  597|     23|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     23|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  598|    618|}
card-coolkey.c:coolkey_v1_get_attribute_len:
  313|   429k|{
  314|   429k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  315|       |
  316|   429k|	*len = 0;
  317|       |	/* don't reference beyond our buffer */
  318|   429k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (318:6): [True: 419k, False: 10.0k]
  ------------------
  319|   419k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|   419k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  320|   419k|	}
  321|  10.0k|	switch (attribute_head->attribute_data_type) {
  322|  4.33k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|  4.33k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (322:2): [True: 4.33k, False: 5.67k]
  ------------------
  323|  4.33k|		if (buf_len < (sizeof(coolkey_attribute_header_t) +2)) {
  ------------------
  |  Branch (323:7): [True: 243, False: 4.09k]
  ------------------
  324|    243|			break;
  325|    243|		}
  326|  4.09k|		*len = bebytes2ushort(attr + sizeof(coolkey_attribute_header_t));
  327|  4.09k|		if (encoded_len) {
  ------------------
  |  Branch (327:7): [True: 3.83k, False: 262]
  ------------------
  328|  3.83k|			*len += 2;
  329|  3.83k|		}
  330|  4.09k|		return SC_SUCCESS;
  ------------------
  |  |   28|  4.09k|#define SC_SUCCESS				0
  ------------------
  331|    473|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|    473|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (331:2): [True: 473, False: 9.54k]
  ------------------
  332|  1.24k|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|  1.24k|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (332:2): [True: 771, False: 9.24k]
  ------------------
  333|       |		/* NOTE: there is no encoded data from TYPE_BOOL_XXX, so we return length 0, but the length
  334|       |		 * of the attribute is actually 1 byte, so if encoded_len == false, return 1 */
  335|  1.24k|		*len = encoded_len ? 0: 1;
  ------------------
  |  Branch (335:10): [True: 1.24k, False: 0]
  ------------------
  336|  1.24k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.24k|#define SC_SUCCESS				0
  ------------------
  337|      0|		break;
  338|  3.67k|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|  3.67k|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (338:2): [True: 3.67k, False: 6.33k]
  ------------------
  339|  3.67k|		*len = 4; /* length is 4 in both encoded length and attribute length */
  340|  3.67k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.67k|#define SC_SUCCESS				0
  ------------------
  341|    754|	default:
  ------------------
  |  Branch (341:2): [True: 754, False: 9.25k]
  ------------------
  342|    754|		break;
  343|  10.0k|	}
  344|    997|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    997|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  345|  10.0k|}
card-coolkey.c:coolkey_read_object:
 1096|  19.4k|{
 1097|  19.4k|	coolkey_read_object_param_t params;
 1098|  19.4k|	u8 *out_ptr;
 1099|  19.4k|	size_t left = 0;
 1100|  19.4k|	size_t len;
 1101|  19.4k|	int r;
 1102|       |
 1103|  19.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  19.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  19.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  19.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 19.4k]
  |  |  ------------------
  ------------------
 1104|       |
 1105|  19.4k|	ulong2bebytes(&params.object_id[0], object_id);
 1106|       |
 1107|  19.4k|	out_ptr = out_buf;
 1108|  19.4k|	left = out_len;
 1109|  20.4k|	do {
 1110|  20.4k|		ulong2bebytes(&params.offset[0], offset);
 1111|  20.4k|		params.length = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
  ------------------
  |  |   70|  20.4k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 12.5k, False: 7.85k]
  |  |  ------------------
  ------------------
 1112|  20.4k|		len = left;
 1113|  20.4k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   72|  20.4k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   88|  20.4k|#define COOLKEY_INS_READ_OBJECT                0x56
  ------------------
 1114|  20.4k|			(u8 *)&params, sizeof(params), &out_ptr, &len, nonce, nonce_size);
 1115|  20.4k|		if (r < 0) {
  ------------------
  |  Branch (1115:7): [True: 15.4k, False: 4.95k]
  ------------------
 1116|  15.4k|			goto fail;
 1117|  15.4k|		}
 1118|       |		/* sanity check to make sure we don't overflow left */
 1119|  4.95k|		if ((left < len) || (len == 0)) {
  ------------------
  |  Branch (1119:7): [True: 84, False: 4.86k]
  |  Branch (1119:23): [True: 2.03k, False: 2.83k]
  ------------------
 1120|  2.11k|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.11k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1121|  2.11k|			goto fail;
 1122|  2.11k|		}
 1123|  2.83k|		out_ptr += len;
 1124|  2.83k|		offset += len;
 1125|  2.83k|		left -= len;
 1126|  2.83k|	} while (left != 0);
  ------------------
  |  Branch (1126:11): [True: 1.00k, False: 1.83k]
  ------------------
 1127|       |
 1128|  1.83k|	return (int)out_len;
 1129|       |
 1130|  17.6k|fail:
 1131|  17.6k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  17.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.6k|	int _ret = r; \
  |  |  |  |  155|  17.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|  17.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.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|  17.6k|	return _ret; \
  |  |  |  |  163|  17.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1132|  17.6k|}
card-coolkey.c:coolkey_apdu_io:
  912|  38.7k|{
  913|  38.7k|	int r;
  914|  38.7k|	sc_apdu_t apdu;
  915|  38.7k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  916|  38.7k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  917|  38.7k|	u8 *rbuf;
  918|  38.7k|	size_t rbuflen;
  919|  38.7k|	int cse = 0;
  920|       |
  921|       |
  922|  38.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  923|       |
  924|  38.7k|	sc_log(card->ctx, "%02x %02x %02x %zu : %zu %zu",
  ------------------
  |  |   71|  38.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__
  |  |  ------------------
  ------------------
  925|  38.7k|			ins, p1, p2, sendbuflen, card->max_send_size, card->max_recv_size);
  926|       |
  927|  38.7k|	rbuf = rbufinitbuf;
  928|  38.7k|	rbuflen = sizeof(rbufinitbuf);
  929|       |
  930|       |	/* if caller provided a buffer and length */
  931|  38.7k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (931:6): [True: 29.7k, False: 9.07k]
  |  Branch (931:17): [True: 29.7k, False: 0]
  |  Branch (931:29): [True: 29.7k, False: 0]
  |  Branch (931:43): [True: 28.4k, False: 1.23k]
  ------------------
  932|  28.4k|		rbuf = *recvbuf;
  933|  28.4k|		rbuflen = *recvbuflen;
  934|  28.4k|	}
  935|       |
  936|  38.7k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (936:6): [True: 29.5k, False: 9.25k]
  |  Branch (936:17): [True: 0, False: 9.25k]
  ------------------
  937|  29.5k|		if (recvbuf) {
  ------------------
  |  Branch (937:7): [True: 20.4k, False: 9.07k]
  ------------------
  938|  20.4k|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  20.4k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  939|  20.4k|		} else {
  940|  9.07k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  9.07k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  941|  9.07k|		}
  942|  29.5k|	} else {
  943|  9.25k|		if (recvbuf) {
  ------------------
  |  Branch (943:7): [True: 9.25k, False: 0]
  ------------------
  944|  9.25k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  9.25k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  945|  9.25k|		} else {
  946|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  947|      0|		}
  948|  9.25k|	}
  949|       |
  950|       |	/* append the nonce if we have it. Coolkey just blindly puts this at the end
  951|       |	 * of the APDU (while adjusting lc). This converts case 1 to case 3. coolkey
  952|       |	 * also always drops le in case 4 (which happens when proto = T0). nonces are
  953|       |	 * never used on case 2 commands, so we can simply append the nonce to the data
  954|       |	 * and we should be fine */
  955|  38.7k|	if (nonce) {
  ------------------
  |  Branch (955:6): [True: 20.4k, False: 18.3k]
  ------------------
  956|  20.4k|		u8 *buf = rsendbuf;
  957|  20.4k|		if (sendbuf) {
  ------------------
  |  Branch (957:7): [True: 20.4k, False: 0]
  ------------------
  958|  20.4k|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   70|  20.4k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 20.4k, False: 0]
  |  |  ------------------
  ------------------
  959|  20.4k|			memcpy(rsendbuf, sendbuf, sendbuflen);
  960|  20.4k|			buf += sendbuflen;
  961|  20.4k|		}
  962|  20.4k|		memcpy(buf, nonce, nonce_len);
  963|  20.4k|		sendbuflen += nonce_len;
  964|  20.4k|		sendbuf =rsendbuf;
  965|  20.4k|	}
  966|       |
  967|  38.7k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  968|       |
  969|  38.7k|	apdu.lc = sendbuflen;
  970|  38.7k|	apdu.datalen = sendbuflen;
  971|  38.7k|	apdu.data = sendbuf;
  972|       |
  973|       |
  974|       |	/* coolkey uses non-standard classes */
  975|  38.7k|	apdu.cla = cla;
  976|       |
  977|  38.7k|	if (recvbuf) {
  ------------------
  |  Branch (977:6): [True: 29.7k, False: 9.07k]
  ------------------
  978|  29.7k|		apdu.resp = rbuf;
  979|  29.7k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (979:13): [True: 8.14k, False: 21.5k]
  ------------------
  980|  29.7k|		apdu.resplen = rbuflen;
  981|  29.7k|	} else {
  982|  9.07k|		 apdu.resp =  rbuf;
  983|  9.07k|		 apdu.le = 0;
  984|  9.07k|		 apdu.resplen = 0;
  985|  9.07k|	}
  986|       |
  987|  38.7k|	sc_log(card->ctx, "calling sc_transmit_apdu flags=%lx le=%zu, resplen=%zu, resp=%p",
  ------------------
  |  |   71|  38.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__
  |  |  ------------------
  ------------------
  988|  38.7k|			apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  989|       |
  990|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  991|  38.7k|	r = sc_transmit_apdu(card, &apdu);
  992|       |
  993|  38.7k|	sc_log(card->ctx, "result r=%d apdu.resplen=%zu sw1=%02x sw2=%02x",
  ------------------
  |  |   71|  38.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__
  |  |  ------------------
  ------------------
  994|  38.7k|			r, apdu.resplen, apdu.sw1, apdu.sw2);
  995|       |
  996|  38.7k|	if (r < 0) {
  ------------------
  |  Branch (996:6): [True: 439, False: 38.3k]
  ------------------
  997|    439|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    439|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  998|    439|		goto err;
  999|    439|	}
 1000|  38.3k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1001|  38.3k|	if (r < 0) {
  ------------------
  |  Branch (1001:6): [True: 22.7k, False: 15.6k]
  ------------------
 1002|  22.7k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  22.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1003|  22.7k|		goto err;
 1004|  22.7k|	}
 1005|       |
 1006|  15.6k|	if (recvbuflen) {
  ------------------
  |  Branch (1006:6): [True: 13.3k, False: 2.26k]
  ------------------
 1007|  13.3k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1007:7): [True: 13.3k, False: 0]
  |  Branch (1007:18): [True: 0, False: 13.3k]
  ------------------
 1008|      0|			*recvbuf =  malloc(apdu.resplen);
 1009|      0|			if (*recvbuf == NULL) {
  ------------------
  |  Branch (1009:8): [True: 0, False: 0]
  ------------------
 1010|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1011|      0|				goto err;
 1012|      0|			}
 1013|      0|			memcpy(*recvbuf, rbuf, apdu.resplen);
 1014|      0|		}
 1015|  13.3k|		*recvbuflen =  apdu.resplen;
 1016|  13.3k|		r = (int)*recvbuflen;
 1017|  13.3k|	}
 1018|       |
 1019|  38.7k|err:
 1020|  38.7k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  38.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  38.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  38.7k|	int _ret = r; \
  |  |  |  |  155|  38.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 27.4k, False: 11.3k]
  |  |  |  |  ------------------
  |  |  |  |  156|  27.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|  23.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 23.1k, False: 4.31k]
  |  |  |  |  ------------------
  |  |  |  |  157|  27.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  27.4k|	} else { \
  |  |  |  |  159|  11.3k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  11.3k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  11.3k|	} \
  |  |  |  |  162|  38.7k|	return _ret; \
  |  |  |  |  163|  38.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1021|  38.7k|}
card-coolkey.c:coolkey_find_object_by_id:
  825|  9.80k|{
  826|  9.80k|	int pos;
  827|  9.80k|	static sc_cardctl_coolkey_object_t cmp = {{
  828|  9.80k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  9.80k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  829|  9.80k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  9.80k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  9.80k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  830|  9.80k|	}, 0, 0, NULL};
  831|       |
  832|  9.80k|	cmp.id = object_id;
  833|  9.80k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (833:6): [True: 4.81k, False: 4.99k]
  ------------------
  834|  4.81k|		return NULL;
  835|       |
  836|  4.99k|	return list_get_at(list, pos);
  837|  9.80k|}
card-coolkey.c:coolkey_find_attribute:
 1416|  50.0k|{
 1417|  50.0k|	u8 object_record_type;
 1418|  50.0k|	CK_ATTRIBUTE_TYPE attr_type = attribute->attribute_type;
 1419|  50.0k|	const u8 *obj = attribute->object->data;
 1420|  50.0k|	const u8 *attr = NULL;
 1421|  50.0k|	size_t buf_len = attribute->object->length;
 1422|  50.0k|	coolkey_object_header_t *object_head;
 1423|  50.0k|	int attribute_count,i;
 1424|  50.0k|	attribute->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1061|  50.0k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
 1425|  50.0k|	attribute->attribute_length = 0;
 1426|  50.0k|	attribute->attribute_value = NULL;
 1427|       |
 1428|  50.0k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  50.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  50.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  50.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  50.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 50.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1429|       |
 1430|  50.0k|	if (obj == NULL) {
  ------------------
  |  Branch (1430:6): [True: 19.2k, False: 30.7k]
  ------------------
 1431|       |		/* cast away const so we can cache the data value */
 1432|  19.2k|		int r = coolkey_fill_object(card, (sc_cardctl_coolkey_object_t *)attribute->object);
 1433|  19.2k|		if (r < 0) {
  ------------------
  |  Branch (1433:7): [True: 17.5k, False: 1.73k]
  ------------------
 1434|  17.5k|			return r;
 1435|  17.5k|		}
 1436|  1.73k|		obj = attribute->object->data;
 1437|  1.73k|		if (obj == NULL) {
  ------------------
  |  Branch (1437:7): [True: 0, False: 1.73k]
  ------------------
 1438|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1439|      0|		}
 1440|  1.73k|	}
 1441|       |
 1442|       |	/* should be a static assert so we catch this at compile time */
 1443|  50.0k|	static_assert(sizeof(coolkey_object_header_t) >= sizeof(coolkey_v0_object_header_t), "internal error");
 1444|       |	/* make sure we have enough of the object to read the record_type */
 1445|  32.4k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (1445:6): [True: 211, False: 32.2k]
  ------------------
 1446|    211|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    211|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1447|    211|	}
 1448|  32.2k|	object_head = (coolkey_object_header_t *)obj;
 1449|  32.2k|	object_record_type = object_head->record_type;
 1450|       |	/* make sure it's a type we recognize */
 1451|  32.2k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  32.2k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  2.79k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (1451:6): [True: 2.79k, False: 29.4k]
  |  Branch (1451:51): [True: 576, False: 2.22k]
  ------------------
 1452|    576|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    576|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1453|    576|	}
 1454|       |
 1455|       |	/*
 1456|       |	 * now loop through all the attributes in the list. first find the start of the list
 1457|       |	 */
 1458|  31.6k|	attr = coolkey_attribute_start(obj, object_record_type, buf_len);
 1459|  31.6k|	if (attr == NULL) {
  ------------------
  |  Branch (1459:6): [True: 358, False: 31.3k]
  ------------------
 1460|    358|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    358|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1461|    358|	}
 1462|  31.3k|	buf_len -= (attr-obj);
 1463|       |
 1464|       |	/* now get the count */
 1465|  31.3k|	attribute_count = coolkey_get_attribute_count(obj, object_record_type, buf_len);
 1466|  41.9k|	for (i=0; i < attribute_count; i++) {
  ------------------
  |  Branch (1466:12): [True: 12.7k, False: 29.1k]
  ------------------
 1467|  12.7k|		size_t record_len = coolkey_get_attribute_record_len(attr, object_record_type, buf_len);
 1468|       |		/* make sure we have the complete record */
 1469|  12.7k|		if (buf_len < record_len || record_len < 4) {
  ------------------
  |  Branch (1469:7): [True: 0, False: 12.7k]
  |  Branch (1469:31): [True: 823, False: 11.9k]
  ------------------
 1470|    823|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    823|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1471|    823|		}
 1472|       |		/* does the attribute match the one we are looking for */
 1473|  11.9k|		if (attr_type == coolkey_get_attribute_type(attr, object_record_type, record_len)) {
  ------------------
  |  Branch (1473:7): [True: 1.36k, False: 10.5k]
  ------------------
 1474|       |			/* yup, return it */
 1475|  1.36k|			return coolkey_get_attribute_data(attr, object_record_type, record_len, attribute);
 1476|  1.36k|		}
 1477|       |		/* go to the next attribute on the list */
 1478|  10.5k|		buf_len -= record_len;
 1479|  10.5k|		attr += record_len;
 1480|  10.5k|	}
 1481|       |	/* not find in attribute list, check the fixed attribute record */
 1482|  29.1k|	if (object_record_type == COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  29.1k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (1482:6): [True: 27.6k, False: 1.51k]
  ------------------
 1483|  27.6k|		unsigned long fixed_attributes = bebytes2ulong(object_head->fixed_attributes_values);
 1484|       |
 1485|  27.6k|		return coolkey_get_attribute_data_fixed(attr_type, fixed_attributes, attribute);
 1486|  27.6k|	}
 1487|  1.51k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  1.51k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.51k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.51k|	int _ret = r; \
  |  |  |  |  155|  1.51k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.51k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.51k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.51k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.51k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.51k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.51k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.51k|	return _ret; \
  |  |  |  |  163|  1.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1488|  1.51k|}
card-coolkey.c:coolkey_attribute_start:
  421|  33.7k|{
  422|  33.7k|	size_t offset = object_record_type == COOLKEY_V1_OBJECT ? sizeof(coolkey_object_header_t) :
  ------------------
  |  |  229|  33.7k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (422:18): [True: 29.4k, False: 4.28k]
  ------------------
  423|  33.7k|			sizeof(coolkey_v0_object_header_t);
  424|       |
  425|  33.7k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  33.7k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  4.28k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (425:6): [True: 4.28k, False: 29.4k]
  |  Branch (425:51): [True: 0, False: 4.28k]
  ------------------
  426|      0|		return NULL;
  427|      0|	}
  428|  33.7k|	if (offset > buf_len) {
  ------------------
  |  Branch (428:6): [True: 358, False: 33.3k]
  ------------------
  429|    358|		return NULL;
  430|    358|	}
  431|  33.3k|	return obj + offset;
  432|  33.7k|}
card-coolkey.c:coolkey_get_attribute_count:
  502|  31.3k|{
  503|  31.3k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  31.3k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (503:6): [True: 2.22k, False: 29.1k]
  ------------------
  504|  2.22k|		return coolkey_v0_get_attribute_count(obj, buf_len);
  505|  2.22k|	}
  506|  29.1k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  29.1k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (506:6): [True: 0, False: 29.1k]
  ------------------
  507|      0|		return 0;
  508|      0|	}
  509|  29.1k|	return coolkey_v1_get_attribute_count(obj, buf_len);
  510|  29.1k|}
card-coolkey.c:coolkey_v0_get_attribute_count:
  440|  2.22k|{
  441|  2.22k|	coolkey_v0_object_header_t *object_head = (coolkey_v0_object_header_t *)obj;
  442|  2.22k|	const u8 *attr;
  443|  2.22k|	int count = 0;
  444|  2.22k|	size_t attribute_data_len;
  445|       |
  446|       |	/* make sure we have enough of the object to read the record_type */
  447|  2.22k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (447:6): [True: 160, False: 2.06k]
  ------------------
  448|    160|		return 0;
  449|    160|	}
  450|       |	/*
  451|       |	 * now loop through all the attributes in the list. first find the start of the list
  452|       |	 */
  453|  2.06k|	attr = coolkey_attribute_start(obj, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|  2.06k|#define COOLKEY_V0_OBJECT 0
  ------------------
  454|  2.06k|	if (attr == NULL) {
  ------------------
  |  Branch (454:6): [True: 0, False: 2.06k]
  ------------------
  455|      0|		return 0;
  456|      0|	}
  457|       |
  458|  2.06k|	buf_len -= (attr-obj);
  459|  2.06k|	attribute_data_len = bebytes2ushort(object_head->attribute_data_len);
  460|  2.06k|	if (buf_len < attribute_data_len) {
  ------------------
  |  Branch (460:6): [True: 350, False: 1.71k]
  ------------------
  461|    350|		return 0;
  462|    350|	}
  463|       |
  464|  4.49k|	while (attribute_data_len) {
  ------------------
  |  Branch (464:9): [True: 3.86k, False: 632]
  ------------------
  465|  3.86k|		size_t len = coolkey_v0_get_attribute_record_len(attr, buf_len);
  466|       |
  467|  3.86k|		if (len == 0) {
  ------------------
  |  Branch (467:7): [True: 0, False: 3.86k]
  ------------------
  468|      0|			break;
  469|      0|		}
  470|       |		/*  This is an error in the token data, don't parse the last attribute */
  471|  3.86k|		if (len > attribute_data_len) {
  ------------------
  |  Branch (471:7): [True: 1.07k, False: 2.78k]
  ------------------
  472|  1.07k|			break;
  473|  1.07k|		}
  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|  2.78k|		if (len > buf_len)
  ------------------
  |  Branch (479:7): [True: 0, False: 2.78k]
  ------------------
  480|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  481|  2.78k|		count++;
  482|  2.78k|		attr += len;
  483|  2.78k|		buf_len -= len;
  484|  2.78k|		attribute_data_len -= len;
  485|  2.78k|	}
  486|  1.71k|	return count;
  487|  1.71k|}
card-coolkey.c:coolkey_v0_get_attribute_record_len:
  380|  6.47k|{
  381|  6.47k|	size_t attribute_len = sizeof(coolkey_v0_attribute_header_t);
  382|  6.47k|	size_t len;
  383|  6.47k|	int r;
  384|       |
  385|  6.47k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  386|  6.47k|	if (r < 0) {
  ------------------
  |  Branch (386:6): [True: 364, False: 6.11k]
  ------------------
  387|    364|		return buf_len; /* skip to the end, ignore the rest of the record */
  388|    364|	}
  389|  6.11k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  6.11k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 1.22k, False: 4.89k]
  |  |  ------------------
  ------------------
  390|  6.47k|}
card-coolkey.c:coolkey_v1_get_attribute_count:
  491|  29.1k|{
  492|  29.1k|	coolkey_object_header_t *object_head = (coolkey_object_header_t *)obj;
  493|       |
  494|  29.1k|	if (buf_len <= sizeof(coolkey_object_header_t)) {
  ------------------
  |  Branch (494:6): [True: 26.3k, False: 2.72k]
  ------------------
  495|  26.3k|		return 0;
  496|  26.3k|	}
  497|  2.72k|	return bebytes2ushort(object_head->attribute_count);
  498|  29.1k|}
card-coolkey.c:coolkey_get_attribute_record_len:
  394|  12.7k|{
  395|  12.7k|	if (obj_record_type ==  COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  12.7k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (395:6): [True: 2.61k, False: 10.1k]
  ------------------
  396|  2.61k|		return coolkey_v0_get_attribute_record_len(attr, buf_len);
  397|  2.61k|	}
  398|  10.1k|	if (obj_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  10.1k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (398:6): [True: 0, False: 10.1k]
  ------------------
  399|      0|		return buf_len; /* skip to the end */
  400|      0|	}
  401|  10.1k|	return coolkey_v1_get_attribute_record_len(attr, buf_len);
  402|  10.1k|}
card-coolkey.c:coolkey_v1_get_attribute_record_len:
  364|   429k|{
  365|   429k|	size_t attribute_len = sizeof(coolkey_attribute_header_t);
  366|   429k|	size_t len = 0;
  367|   429k|	int r;
  368|       |
  369|   429k|	r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 1);
  370|   429k|	if (r < 0) {
  ------------------
  |  Branch (370:6): [True: 420k, False: 8.75k]
  ------------------
  371|   420k|		return buf_len; /* skip to the end, ignore the rest of the record */
  372|   420k|	}
  373|       |
  374|  8.75k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  8.75k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 592, False: 8.16k]
  |  |  ------------------
  ------------------
  375|   429k|}
card-coolkey.c:coolkey_get_attribute_data_fixed:
  674|  27.6k|																sc_cardctl_coolkey_attribute_t *attr_out) {
  675|  27.6k|	unsigned long cka_id = fixed_attributes & 0xf;
  676|  27.6k|	unsigned long cka_class = ((fixed_attributes) >> 4) & 0x7;
  677|  27.6k|	unsigned long mask, bit;
  678|       |
  679|  27.6k|	if (attr_type == CKA_ID) {
  ------------------
  |  |  161|  27.6k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (679:6): [True: 2.81k, False: 24.8k]
  ------------------
  680|  2.81k|		attr_out->attribute_length = 1;
  681|  2.81k|		attr_out->attribute_value= &coolkey_static_cka_id[cka_id];
  682|  2.81k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.81k|#define SC_SUCCESS				0
  ------------------
  683|  2.81k|	}
  684|  24.8k|	if (attr_type == CKA_CLASS) {
  ------------------
  |  |  137|  24.8k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (684:6): [True: 7.92k, False: 16.8k]
  ------------------
  685|  7.92k|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1062|  7.92k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  686|  7.92k|		attr_out->attribute_length = 4;
  687|  7.92k|		attr_out->attribute_value = coolkey_static_cka_class[cka_class].class_value;
  688|  7.92k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.92k|#define SC_SUCCESS				0
  ------------------
  689|  7.92k|	}
  690|       |	/* If it matched, it must be one of the booleans */
  691|  16.8k|	mask = coolkey_static_cka_class[cka_class].boolean_mask;
  692|  16.8k|	bit = coolkey_get_fixed_boolean_bit(attr_type);
  693|       |	/* attribute isn't in the list */
  694|  16.8k|	if ((bit & mask) == 0) {
  ------------------
  |  Branch (694:6): [True: 6.42k, False: 10.4k]
  ------------------
  695|  6.42k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  6.42k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  696|  6.42k|	}
  697|  10.4k|	attr_out->attribute_length = 1;
  698|  10.4k|	attr_out->attribute_value = bit & fixed_attributes ? &coolkey_static_true : &coolkey_static_false;
  ------------------
  |  Branch (698:30): [True: 3.35k, False: 7.10k]
  ------------------
  699|  10.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  10.4k|#define SC_SUCCESS				0
  ------------------
  700|  16.8k|}
card-coolkey.c:coolkey_get_fixed_boolean_bit:
  620|  16.8k|{
  621|  16.8k|	switch(type) {
  622|      0|	case CKA_TOKEN:               return 0x00000080;
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (622:2): [True: 0, False: 16.8k]
  ------------------
  623|  1.15k|	case CKA_PRIVATE:             return 0x00000100;
  ------------------
  |  |  139|  1.15k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (623:2): [True: 1.15k, False: 15.7k]
  ------------------
  624|  1.21k|	case CKA_MODIFIABLE:          return 0x00000200;
  ------------------
  |  |  197|  1.21k|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (624:2): [True: 1.21k, False: 15.6k]
  ------------------
  625|    815|	case CKA_DERIVE:              return 0x00000400;
  ------------------
  |  |  171|    815|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (625:2): [True: 815, False: 16.0k]
  ------------------
  626|    815|	case CKA_LOCAL:               return 0x00000800;
  ------------------
  |  |  193|    815|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (626:2): [True: 815, False: 16.0k]
  ------------------
  627|    814|	case CKA_ENCRYPT:             return 0x00001000;
  ------------------
  |  |  163|    814|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (627:2): [True: 814, False: 16.0k]
  ------------------
  628|    815|	case CKA_DECRYPT:             return 0x00002000;
  ------------------
  |  |  164|    815|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (628:2): [True: 815, False: 16.0k]
  ------------------
  629|    815|	case CKA_WRAP:                return 0x00004000;
  ------------------
  |  |  165|    815|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (629:2): [True: 815, False: 16.0k]
  ------------------
  630|    815|	case CKA_UNWRAP:              return 0x00008000;
  ------------------
  |  |  166|    815|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (630:2): [True: 815, False: 16.0k]
  ------------------
  631|    815|	case CKA_SIGN:                return 0x00010000;
  ------------------
  |  |  167|    815|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (631:2): [True: 815, False: 16.0k]
  ------------------
  632|    815|	case CKA_SIGN_RECOVER:        return 0x00020000;
  ------------------
  |  |  168|    815|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (632:2): [True: 815, False: 16.0k]
  ------------------
  633|    815|	case CKA_VERIFY:              return 0x00040000;
  ------------------
  |  |  169|    815|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (633:2): [True: 815, False: 16.0k]
  ------------------
  634|    815|	case CKA_VERIFY_RECOVER:      return 0x00080000;
  ------------------
  |  |  170|    815|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (634:2): [True: 815, False: 16.0k]
  ------------------
  635|    815|	case CKA_SENSITIVE:           return 0x00100000;
  ------------------
  |  |  162|    815|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (635:2): [True: 815, False: 16.0k]
  ------------------
  636|    815|	case CKA_ALWAYS_SENSITIVE:    return 0x00200000;
  ------------------
  |  |  195|    815|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (636:2): [True: 815, False: 16.0k]
  ------------------
  637|    815|	case CKA_EXTRACTABLE:         return 0x00400000;
  ------------------
  |  |  192|    815|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (637:2): [True: 815, False: 16.0k]
  ------------------
  638|    815|	case CKA_NEVER_EXTRACTABLE:   return 0x00800000;
  ------------------
  |  |  194|    815|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (638:2): [True: 815, False: 16.0k]
  ------------------
  639|  3.10k|	default: break;
  ------------------
  |  Branch (639:2): [True: 3.10k, False: 13.7k]
  ------------------
  640|  16.8k|	}
  641|  3.10k|	return 0; /* return no bits */
  642|  16.8k|}
card-coolkey.c:sc_get_driver:
 2440|  14.1k|{
 2441|  14.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2442|       |
 2443|  14.1k|	coolkey_ops = *iso_drv->ops;
 2444|  14.1k|	coolkey_ops.match_card = coolkey_match_card;
 2445|  14.1k|	coolkey_ops.init = coolkey_init;
 2446|  14.1k|	coolkey_ops.finish = coolkey_finish;
 2447|       |
 2448|  14.1k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2449|  14.1k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2450|  14.1k|	coolkey_ops.read_binary = coolkey_read_binary;
 2451|  14.1k|	coolkey_ops.write_binary = coolkey_write_binary;
 2452|  14.1k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2453|  14.1k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2454|  14.1k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2455|  14.1k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2456|  14.1k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2457|  14.1k|	coolkey_ops.check_sw = coolkey_check_sw;
 2458|  14.1k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2459|  14.1k|	coolkey_ops.logout = coolkey_logout;
 2460|  14.1k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2461|       |
 2462|  14.1k|	return &coolkey_drv;
 2463|  14.1k|}
card-coolkey.c:coolkey_match_card:
 2279|  6.51k|{
 2280|  6.51k|	int r;
 2281|       |
 2282|  6.51k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.51k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.51k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.51k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.51k]
  |  |  ------------------
  ------------------
 2283|       |
 2284|  6.51k|	r = coolkey_select_applet(card);
 2285|  6.51k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  6.51k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2285:6): [True: 1.02k, False: 5.48k]
  ------------------
 2286|  1.02k|		sc_apdu_t apdu;
 2287|       |
 2288|       |		/* The GET STATUS INS with P1 = 1 returns invalid instruction (0x6D00)
 2289|       |		 * on Coolkey applet (reserved for GetMemory function),
 2290|       |		 * while incorrect P1 (0x9C10) on Muscle applets
 2291|       |		 */
 2292|  1.02k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|  1.02k|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   79|  1.02k|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2293|  1.02k|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   72|  1.02k|#define COOLKEY_CLASS           0xb0
  ------------------
 2294|  1.02k|		apdu.le = 0x00;
 2295|  1.02k|		apdu.resplen = 0;
 2296|  1.02k|		apdu.resp = NULL;
 2297|  1.02k|		r = sc_transmit_apdu(card, &apdu);
 2298|  1.02k|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|  2.05k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2298:7): [True: 1.02k, False: 1]
  |  Branch (2298:26): [True: 983, False: 43]
  |  Branch (2298:46): [True: 982, False: 1]
  ------------------
 2299|    982|			return 1;
 2300|    982|		}
 2301|     45|		return 0;
 2302|  1.02k|	}
 2303|  5.48k|	return 0;
 2304|  6.51k|}
card-coolkey.c:coolkey_select_applet:
 1070|  9.07k|{
 1071|  9.07k|	u8 aid[] = { 0x62, 0x76, 0x01, 0xff, 0x00, 0x00, 0x00 };
 1072|  9.07k|	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   71|  9.07k|#define ISO7816_CLASS           0x00
  ------------------
              	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   75|  9.07k|#define ISO7816_INS_SELECT_FILE 0xa4
  ------------------
 1073|  9.07k|			&aid[0], sizeof(aid), NULL, NULL,  NULL, 0);
 1074|  9.07k|}
card-coolkey.c:coolkey_init:
 2308|    982|{
 2309|    982|	int r;
 2310|    982|	unsigned long flags;
 2311|    982|	unsigned long ext_flags;
 2312|    982|	coolkey_private_data_t * priv;
 2313|       |
 2314|    982|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    982|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    982|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    982|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 982]
  |  |  ------------------
  ------------------
 2315|       |
 2316|    982|	r = coolkey_initialize(card);
 2317|    982|	if (r < 0) {
  ------------------
  |  Branch (2317:6): [True: 426, False: 556]
  ------------------
 2318|    426|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2319|    426|	}
 2320|       |
 2321|    556|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2322|       |
 2323|       |	/* set Token Major/minor version */
 2324|    556|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    556|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2325|       |
 2326|    556|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2327|    556|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2328|    556|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2329|       |
 2330|    556|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|    556|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|    556|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|    556|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    556|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2331|    556|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    556|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    556|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2332|       |
 2333|    556|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2334|    556|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2335|    556|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2336|       |
 2337|       |
 2338|    556|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    556|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2339|    556|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2339:6): [True: 368, False: 188]
  ------------------
 2340|    368|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    368|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2341|    368|	}
 2342|       |
 2343|    556|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    556|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    556|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    556|	int _ret = r; \
  |  |  |  |  155|    556|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 556, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    556|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 556]
  |  |  |  |  ------------------
  |  |  |  |  157|    556|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    556|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    556|	return _ret; \
  |  |  |  |  163|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2344|    556|}
card-coolkey.c:coolkey_initialize:
 2148|    982|{
 2149|    982|	int r;
 2150|    982|	coolkey_private_data_t *priv = NULL;
 2151|    982|	coolkey_life_cycle_t life_cycle;
 2152|    982|	coolkey_object_info_t object_info;
 2153|    982|	int combined_processed = 0;
 2154|       |
 2155|       |	/* already found? */
 2156|    982|	if (card->drv_data) {
  ------------------
  |  Branch (2156:6): [True: 0, False: 982]
  ------------------
 2157|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2158|      0|	}
 2159|    982|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|    982|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2160|       |
 2161|    982|	priv = coolkey_new_private_data();
 2162|    982|	if (priv == NULL) {
  ------------------
  |  Branch (2162:6): [True: 0, False: 982]
  ------------------
 2163|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2164|      0|		goto cleanup;
 2165|      0|	}
 2166|    982|	r = coolkey_get_life_cycle(card, &life_cycle);
 2167|    982|	if (r < 0) {
  ------------------
  |  Branch (2167:6): [True: 66, False: 916]
  ------------------
 2168|     66|		goto cleanup;
 2169|     66|	}
 2170|       |
 2171|       |	/* Select a coolkey read the coolkey objects out */
 2172|    916|	r = coolkey_select_applet(card);
 2173|    916|	if (r < 0) {
  ------------------
  |  Branch (2173:6): [True: 6, False: 910]
  ------------------
 2174|      6|		goto cleanup;
 2175|      6|	}
 2176|       |
 2177|    910|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2178|    910|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2179|    910|	priv->pin_count = life_cycle.pin_count;
 2180|    910|	priv->life_cycle = life_cycle.life_cycle;
 2181|       |
 2182|       |	/* walk down the list of objects and read them off the token */
 2183|    910|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  104|    910|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2184|  8.18k|	while (r >= 0) {
  ------------------
  |  Branch (2184:9): [True: 7.43k, False: 745]
  ------------------
 2185|  7.43k|		unsigned long object_id;
 2186|  7.43k|		unsigned long object_len;
 2187|       |
 2188|       |		/* The card did not return what we expected: Lets try other objects */
 2189|  7.43k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2189:7): [True: 10, False: 7.42k]
  ------------------
 2190|     10|			break;
 2191|       |
 2192|       |		/* TODO also look at the ACL... */
 2193|       |
 2194|  7.42k|		object_id = bebytes2ulong(object_info.object_id);
 2195|  7.42k|		object_len = bebytes2ulong(object_info.object_length);
 2196|       |		/* Avoid insanely large data */
 2197|  7.42k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  7.42k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2197:7): [True: 23, False: 7.40k]
  ------------------
 2198|     23|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     23|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2199|     23|			goto cleanup;
 2200|     23|		}
 2201|       |
 2202|       |		/* the combined object is a single object that can store the other objects.
 2203|       |		 * most coolkeys provisioned by TPS has a single combined object that is
 2204|       |		 * compressed greatly increasing the effectiveness of compress (since lots
 2205|       |		 * of certs on the token share the same Subject and Issuer DN's). We now
 2206|       |		 * process it separately so that we can have both combined objects managed
 2207|       |		 * by TPS and user managed certs on the same token */
 2208|  7.40k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  109|  7.40k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2208:7): [True: 140, False: 7.26k]
  ------------------
 2209|    140|			u8 *object = malloc(object_len);
 2210|    140|			if (object == NULL) {
  ------------------
  |  Branch (2210:8): [True: 0, False: 140]
  ------------------
 2211|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2212|      0|				break;
 2213|      0|			}
 2214|    140|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  109|    140|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2215|    140|				priv->nonce, sizeof(priv->nonce));
 2216|    140|			if (r < 0) {
  ------------------
  |  Branch (2216:8): [True: 56, False: 84]
  ------------------
 2217|     56|				free(object);
 2218|     56|				break;
 2219|     56|			}
 2220|     84|			r = coolkey_process_combined_object(card, priv, object, r);
 2221|     84|			free(object);
 2222|     84|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     84|#define SC_SUCCESS				0
  ------------------
  |  Branch (2222:8): [True: 76, False: 8]
  ------------------
 2223|     76|				break;
 2224|     76|			}
 2225|      8|			combined_processed = 1;
 2226|  7.26k|		} else {
 2227|  7.26k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   71|  7.26k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2228|  7.26k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2229|  7.26k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  7.26k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2229:8): [True: 3.05k, False: 4.20k]
  ------------------
 2230|  3.05k|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|  3.05k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2231|  7.26k|		}
 2232|       |
 2233|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2234|  7.27k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  105|  7.27k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2235|  7.27k|	}
 2236|    887|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    887|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2236:6): [True: 315, False: 572]
  ------------------
 2237|       |		/* This means the card does not cooperate at all: bail out */
 2238|    315|		if (r >= 0) {
  ------------------
  |  Branch (2238:7): [True: 10, False: 305]
  ------------------
 2239|     10|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     10|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2240|     10|		}
 2241|    315|		goto cleanup;
 2242|    315|	}
 2243|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2244|    572|	if (!combined_processed) {
  ------------------
  |  Branch (2244:6): [True: 571, False: 1]
  ------------------
 2245|    571|		global_platform_cplc_data_t cplc_data;
 2246|       |		/* select the card manager, because a card with applet only will have
 2247|       |		   already selected the coolkey applet */
 2248|       |
 2249|    571|		r = gp_select_card_manager(card);
 2250|    571|		if (r < 0) {
  ------------------
  |  Branch (2250:7): [True: 3, False: 568]
  ------------------
 2251|      3|			goto cleanup;
 2252|      3|		}
 2253|       |
 2254|    568|		r = gp_get_cplc_data(card, &cplc_data);
 2255|    568|		if (r < 0) {
  ------------------
  |  Branch (2255:7): [True: 13, False: 555]
  ------------------
 2256|     13|			goto cleanup;
 2257|     13|		}
 2258|    555|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2259|    555|		priv->token_name = (u8 *)strdup("COOLKEY");
 2260|    555|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2260:7): [True: 0, False: 555]
  ------------------
 2261|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2262|      0|			goto cleanup;
 2263|      0|		}
 2264|    555|		priv->token_name_length = sizeof("COOLKEY")-1;
 2265|    555|	}
 2266|    556|	card->drv_data = priv;
 2267|    556|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    556|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    556|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    556|	int _ret = r; \
  |  |  |  |  155|    556|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 556, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    556|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 556]
  |  |  |  |  ------------------
  |  |  |  |  157|    556|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    556|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    556|	return _ret; \
  |  |  |  |  163|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2268|       |
 2269|    426|cleanup:
 2270|    426|	if (priv) {
  ------------------
  |  Branch (2270:6): [True: 426, False: 0]
  ------------------
 2271|    426|		coolkey_free_private_data(priv);
 2272|    426|	}
 2273|    426|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    426|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    426|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    426|	int _ret = r; \
  |  |  |  |  155|    426|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 426, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    426|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2274|    426|}
card-coolkey.c:coolkey_new_private_data:
  772|    982|{
  773|    982|	coolkey_private_data_t *priv;
  774|       |
  775|       |	/* allocate priv and zero all the fields */
  776|    982|	priv = calloc(1, sizeof(coolkey_private_data_t));
  777|    982|	if (!priv)
  ------------------
  |  Branch (777:6): [True: 0, False: 982]
  ------------------
  778|      0|		return NULL;
  779|       |
  780|       |	/* set other fields as appropriate */
  781|    982|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|    982|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  782|    982|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (782:6): [True: 0, False: 982]
  ------------------
  783|    982|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 982]
  ------------------
  784|    982|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (784:6): [True: 0, False: 982]
  ------------------
  785|      0|		coolkey_free_private_data(priv);
  786|      0|		return NULL;
  787|      0|	}
  788|       |
  789|    982|	return priv;
  790|    982|}
card-coolkey.c:coolkey_get_life_cycle:
 1028|    982|{
 1029|    982|	coolkey_status_t status;
 1030|    982|	u8 *receive_buf;
 1031|    982|	size_t receive_len;
 1032|    982|	int len;
 1033|       |
 1034|    982|	receive_len = sizeof(*life_cycle);
 1035|    982|	receive_buf = (u8 *)life_cycle;
 1036|    982|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|    982|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|    982|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1037|    982|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1038|    982|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1038:6): [True: 909, False: 73]
  ------------------
 1039|    909|		return SC_SUCCESS;
  ------------------
  |  |   28|    909|#define SC_SUCCESS				0
  ------------------
 1040|    909|	}
 1041|       |
 1042|     73|	receive_len = 1;
 1043|     73|	receive_buf = &life_cycle->life_cycle;
 1044|     73|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|     73|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|     73|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1045|     73|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1046|     73|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1046:6): [True: 49, False: 24]
  ------------------
 1047|     49|		return len;
 1048|     49|	}
 1049|     24|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1049:6): [True: 4, False: 20]
  ------------------
 1050|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1051|      4|	}
 1052|     20|	receive_len = sizeof(status);
 1053|     20|	receive_buf = (u8 *)&status;
 1054|     20|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   72|     20|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   79|     20|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1055|     20|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1056|     20|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1056:6): [True: 6, False: 14]
  ------------------
 1057|      6|		return len;
 1058|      6|	}
 1059|     14|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1059:6): [True: 7, False: 7]
  ------------------
 1060|      7|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      7|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1061|      7|	}
 1062|      7|	life_cycle->protocol_version_major = status.protocol_version_major;
 1063|      7|	life_cycle->protocol_version_minor = status.protocol_version_minor;
 1064|      7|	life_cycle->pin_count = status.pin_count;
 1065|      7|	return SC_SUCCESS;
  ------------------
  |  |   28|      7|#define SC_SUCCESS				0
  ------------------
 1066|     14|}
card-coolkey.c:coolkey_list_object:
 2135|  8.18k|{
 2136|  8.18k|	u8 *rbuf = (u8 *) object_info;
 2137|  8.18k|	size_t rbuflen = sizeof(*object_info);
 2138|       |
 2139|  8.18k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   72|  8.18k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   81|  8.18k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2140|  8.18k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2141|       |
 2142|  8.18k|}
card-coolkey.c:coolkey_process_combined_object:
 2000|     84|{
 2001|     84|	coolkey_combined_header_t *header = (coolkey_combined_header_t *)object;
 2002|     84|	unsigned short compressed_offset;
 2003|     84|	unsigned short compressed_length;
 2004|     84|	unsigned short compressed_type;
 2005|     84|	size_t object_offset;
 2006|     84|	unsigned short object_count;
 2007|     84|	coolkey_decompressed_header_t *decompressed_header;
 2008|     84|	u8 *decompressed_object = NULL;
 2009|     84|	size_t decompressed_object_len = 0;
 2010|     84|	int free_decompressed = 0;
 2011|     84|	int i, r;
 2012|       |
 2013|     84|	if (object_length < sizeof(coolkey_combined_header_t)) {
  ------------------
  |  Branch (2013:6): [True: 3, False: 81]
  ------------------
 2014|      3|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      3|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2015|      3|	}
 2016|     81|	compressed_offset = bebytes2ushort(header->compression_offset);
 2017|     81|	compressed_length = bebytes2ushort(header->compression_length);
 2018|     81|	compressed_type   = bebytes2ushort(header->compression_type);
 2019|       |
 2020|     81|	if ((((size_t)compressed_offset) + (size_t)compressed_length) >  object_length) {
  ------------------
  |  Branch (2020:6): [True: 6, False: 75]
  ------------------
 2021|      6|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      6|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2022|      6|	}
 2023|       |
 2024|       |	/* store the CUID */
 2025|     75|	memcpy(&priv->cuid, &header->cuid, sizeof(priv->cuid));
 2026|       |
 2027|     75|	if (compressed_type == COOLKEY_COMPRESSION_ZLIB) {
  ------------------
  |  |  180|     75|#define COOLKEY_COMPRESSION_ZLIB 1
  ------------------
  |  Branch (2027:6): [True: 3, False: 72]
  ------------------
 2028|      3|#ifdef ENABLE_ZLIB
 2029|      3|		r = sc_decompress_alloc(&decompressed_object, &decompressed_object_len, &object[compressed_offset], compressed_length, COMPRESSION_AUTO);
  ------------------
  |  |   26|      3|#define COMPRESSION_AUTO	0
  ------------------
 2030|      3|		if (r)
  ------------------
  |  Branch (2030:7): [True: 3, False: 0]
  ------------------
 2031|      3|			goto done;
 2032|      0|		free_decompressed = 1;
 2033|       |#else
 2034|       |		sc_log(card->ctx, "Coolkey compression not supported, no zlib");
 2035|       |		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2036|       |#endif
 2037|     72|	}  else {
 2038|     72|		decompressed_object =&object[compressed_offset];
 2039|     72|		decompressed_object_len = (size_t) compressed_length;
 2040|     72|	}
 2041|       |
 2042|     72|	decompressed_header = (coolkey_decompressed_header_t *)decompressed_object;
 2043|       |
 2044|     72|	if (decompressed_object_len < sizeof(coolkey_decompressed_header_t)) {
  ------------------
  |  Branch (2044:6): [True: 9, False: 63]
  ------------------
 2045|      9|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      9|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2046|      9|		goto done;
 2047|      9|	}
 2048|     63|	object_offset = bebytes2ushort(decompressed_header->object_offset);
 2049|     63|	object_count = bebytes2ushort(decompressed_header->object_count);
 2050|       |
 2051|       |
 2052|       |	/*
 2053|       |	 * using 2 different tests here so we can log different errors if logging is
 2054|       |	 * turned on.
 2055|       |	 */
 2056|       |	/* make sure token_name doesn't overrun the buffer */
 2057|     63|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2057:6): [True: 0, False: 63]
  ------------------
 2058|     63|		offsetof(coolkey_decompressed_header_t, token_name) > decompressed_object_len) {
 2059|      0|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2060|      0|		goto done;
 2061|      0|	}
 2062|       |	/* make sure it doesn't overlap the object space */
 2063|     63|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2063:6): [True: 8, False: 55]
  ------------------
 2064|     63|		offsetof(coolkey_decompressed_header_t, token_name) > object_offset) {
 2065|      8|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      8|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2066|      8|		goto done;
 2067|      8|	}
 2068|       |
 2069|       |	/* store the token name in the priv structure so the emulator can set it */
 2070|     55|	free(priv->token_name);
 2071|     55|	priv->token_name = malloc(decompressed_header->token_name_length+1);
 2072|     55|	if (priv->token_name == NULL) {
  ------------------
  |  Branch (2072:6): [True: 0, False: 55]
  ------------------
 2073|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2074|      0|		goto done;
 2075|      0|	}
 2076|     55|	memcpy(priv->token_name, &decompressed_header->token_name[0],
 2077|     55|							decompressed_header->token_name_length);
 2078|     55|	priv->token_name[decompressed_header->token_name_length] = '\0';
 2079|     55|	priv->token_name_length = decompressed_header->token_name_length;
 2080|       |
 2081|     55|	if (object_count > decompressed_object_len / sizeof(coolkey_combined_object_header_t)) {
  ------------------
  |  Branch (2081:6): [True: 19, False: 36]
  ------------------
 2082|     19|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     19|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2083|     19|		goto done;
 2084|     19|	}
 2085|       |
 2086|     87|	for (i=0; i < object_count; i++) {
  ------------------
  |  Branch (2086:12): [True: 79, False: 8]
  ------------------
 2087|     79|		u8 *current_object = NULL;
 2088|     79|		coolkey_combined_object_header_t *object_header = NULL;
 2089|     79|		unsigned long object_id;
 2090|     79|		int current_object_len;
 2091|       |
 2092|       |		/* Can we read the object header at all? */
 2093|     79|		if ((object_offset + sizeof(coolkey_combined_object_header_t)) > decompressed_object_len) {
  ------------------
  |  Branch (2093:7): [True: 25, False: 54]
  ------------------
 2094|     25|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     25|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2095|     25|			goto done;
 2096|     25|		}
 2097|       |
 2098|     54|		current_object = &decompressed_object[object_offset];
 2099|     54|		object_header = (coolkey_combined_object_header_t *)current_object;
 2100|       |
 2101|       |		/* Parse object ID */
 2102|     54|		object_id = bebytes2ulong(object_header->object_id);
 2103|       |
 2104|       |		/* figure out how big it is */
 2105|     54|		r = coolkey_v1_get_object_length(current_object, decompressed_object_len-object_offset);
 2106|     54|		if (r < 0) {
  ------------------
  |  Branch (2106:7): [True: 0, False: 54]
  ------------------
 2107|      0|			goto done;
 2108|      0|		}
 2109|     54|		if ((size_t)r + object_offset > decompressed_object_len) {
  ------------------
  |  Branch (2109:7): [True: 0, False: 54]
  ------------------
 2110|      0|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2111|      0|			goto done;
 2112|      0|		}
 2113|     54|		current_object_len = r;
 2114|     54|		object_offset += current_object_len;
 2115|       |
 2116|       |		/* record this object */
 2117|     54|		sc_log(card->ctx, "Add new object id=%ld", object_id);
  ------------------
  |  |   71|     54|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2118|     54|		r = coolkey_add_object(priv, object_id, current_object, current_object_len, 1);
 2119|     54|		if (r) {
  ------------------
  |  Branch (2119:7): [True: 3, False: 51]
  ------------------
 2120|      3|			goto done;
 2121|      3|		}
 2122|       |
 2123|     54|	}
 2124|      8|	r = SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
 2125|       |
 2126|     75|done:
 2127|     75|	if (free_decompressed) {
  ------------------
  |  Branch (2127:6): [True: 0, False: 75]
  ------------------
 2128|      0|		free(decompressed_object);
 2129|      0|	}
 2130|     75|	return r;
 2131|      8|}
card-coolkey.c:coolkey_v1_get_object_length:
  706|     54|{
  707|     54|	coolkey_combined_object_header_t *object_head = (coolkey_combined_object_header_t *) obj;
  708|     54|	int attribute_count;
  709|     54|	u8 *current_attribute;
  710|     54|	int j;
  711|     54|	size_t len;
  712|       |
  713|     54|	len = sizeof(coolkey_combined_object_header_t);
  714|     54|	if (buf_len <= len) {
  ------------------
  |  Branch (714:6): [True: 1, False: 53]
  ------------------
  715|      1|		return (int)buf_len;
  716|      1|	}
  717|     53|	attribute_count = bebytes2ushort(object_head->attribute_count);
  718|     53|	buf_len -= len;
  719|       |
  720|   418k|	for (current_attribute = obj + len, j = 0; j < attribute_count; j++) {
  ------------------
  |  Branch (720:45): [True: 418k, False: 53]
  ------------------
  721|   418k|		size_t attribute_len = coolkey_v1_get_attribute_record_len(current_attribute, buf_len);
  722|       |
  723|   418k|		len += attribute_len;
  724|   418k|		current_attribute += attribute_len;
  725|   418k|		buf_len -= attribute_len;
  726|   418k|	}
  727|     53|	return (int)len;
  728|     54|}
card-coolkey.c:coolkey_add_object:
 1959|  7.32k|{
 1960|  7.32k|	sc_cardctl_coolkey_object_t new_object;
 1961|  7.32k|	int r;
 1962|       |
 1963|  7.32k|	memset(&new_object, 0, sizeof(new_object));
 1964|  7.32k|	new_object.path = coolkey_template_path;
 1965|  7.32k|	new_object.path.len = 4;
 1966|  7.32k|	ulong2bebytes(new_object.path.value, object_id);
 1967|  7.32k|	new_object.id = object_id;
 1968|  7.32k|	new_object.length = object_length;
 1969|       |
 1970|       |	/* The object ID needs to be unique */
 1971|  7.32k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1971:6): [True: 3.06k, False: 4.25k]
  ------------------
 1972|  3.06k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  3.06k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1973|  3.06k|	}
 1974|       |
 1975|  4.25k|	if (object_data) {
  ------------------
  |  Branch (1975:6): [True: 51, False: 4.20k]
  ------------------
 1976|     51|		new_object.data = malloc(object_length + add_v1_record);
 1977|     51|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1977:7): [True: 0, False: 51]
  ------------------
 1978|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1979|      0|		}
 1980|     51|		if (add_v1_record) {
  ------------------
  |  Branch (1980:7): [True: 51, False: 0]
  ------------------
 1981|     51|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  229|     51|#define COOLKEY_V1_OBJECT 1
  ------------------
 1982|     51|			new_object.length++;
 1983|     51|		}
 1984|     51|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 1985|     51|	}
 1986|       |
 1987|  4.25k|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 1988|  4.25k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  4.25k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1988:6): [True: 0, False: 4.25k]
  ------------------
 1989|       |		/* if we didn't successfully put the object on the list,
 1990|       |		 * the data space didn't get adopted. free it before we return */
 1991|      0|		free(new_object.data);
 1992|       |		new_object.data = NULL;
 1993|      0|	}
 1994|  4.25k|	return r;
 1995|  4.25k|}
card-coolkey.c:coolkey_add_object_to_list:
  816|  4.25k|{
  817|  4.25k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (817:6): [True: 0, False: 4.25k]
  ------------------
  818|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  819|  4.25k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.25k|#define SC_SUCCESS				0
  ------------------
  820|  4.25k|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1078|    555|{
 1079|    555|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1080|    555|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1081|    555|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1082|    555|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1083|    555|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1084|    555|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1085|    555|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1086|    555|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1087|    555|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1088|    555|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1089|    555|}
card-coolkey.c:coolkey_free_private_data:
  793|    982|{
  794|    982|	list_t *l = &priv->objects_list;
  795|    982|	sc_cardctl_coolkey_object_t *o;
  796|       |
  797|       |	/* Clean up the allocated memory in the items */
  798|    982|	list_iterator_start(l);
  799|  5.24k|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (799:9): [True: 4.25k, False: 982]
  ------------------
  800|  4.25k|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  801|  4.25k|		free(o->data);
  802|  4.25k|		o->data = NULL;
  803|  4.25k|	}
  804|    982|	list_iterator_stop(l);
  805|       |
  806|    982|	list_destroy(&priv->objects_list);
  807|    982|	free(priv->token_name);
  808|    982|	free(priv);
  809|    982|	return;
  810|    982|}
card-coolkey.c:coolkey_finish:
 1947|    556|{
 1948|    556|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    556|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1949|       |
 1950|    556|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    556|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    556|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    556|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 556]
  |  |  ------------------
  ------------------
 1951|    556|	if (priv) {
  ------------------
  |  Branch (1951:6): [True: 556, False: 0]
  ------------------
 1952|    556|		coolkey_free_private_data(priv);
 1953|    556|	}
 1954|    556|	return SC_SUCCESS;
  ------------------
  |  |   28|    556|#define SC_SUCCESS				0
  ------------------
 1955|    556|}
card-coolkey.c:coolkey_select_file:
 1900|  1.64k|{
 1901|  1.64k|	int r;
 1902|  1.64k|	struct sc_file *file = NULL;
 1903|  1.64k|	coolkey_private_data_t *priv;
 1904|  1.64k|	unsigned long object_id;
 1905|       |
 1906|  1.64k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1906:6): [True: 0, False: 1.64k]
  |  Branch (1906:22): [True: 0, False: 1.64k]
  ------------------
 1907|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1908|       |
 1909|  1.64k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1910|       |
 1911|  1.64k|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.64k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1912|       |
 1913|  1.64k|	if (in_path->len != 4) {
  ------------------
  |  Branch (1913:6): [True: 3, False: 1.64k]
  ------------------
 1914|      3|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      3|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1915|      3|	}
 1916|  1.64k|	r = coolkey_select_applet(card);
 1917|  1.64k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.64k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1917:6): [True: 1.31k, False: 332]
  ------------------
 1918|  1.31k|		return r;
 1919|  1.31k|	}
 1920|    332|	object_id = bebytes2ulong(in_path->value);
 1921|    332|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1922|    332|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1922:6): [True: 314, False: 18]
  ------------------
 1923|    314|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    314|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1924|    314|	}
 1925|       |
 1926|     18|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|     18|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1927|     18|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  111|     18|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1927:6): [True: 0, False: 18]
  ------------------
 1928|      0|		priv->key_id = coolkey_get_key_id(object_id);
 1929|      0|	}
 1930|     18|	if (file_out) {
  ------------------
  |  Branch (1930:6): [True: 17, False: 1]
  ------------------
 1931|     17|		file = sc_file_new();
 1932|     17|		if (file == NULL)
  ------------------
  |  Branch (1932:7): [True: 0, False: 17]
  ------------------
 1933|     17|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1934|     17|		file->path = *in_path;
 1935|       |		/* this could be like the FCI */
 1936|     17|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     17|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1937|     17|		file->shareable = 0;
 1938|     17|		file->ef_structure = 0;
 1939|     17|		file->size = priv->obj->length;
 1940|     17|		*file_out = file;
 1941|     17|	}
 1942|       |
 1943|     18|	return SC_SUCCESS;
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
 1944|     18|}
card-coolkey.c:coolkey_class:
 1873|     18|static u8 coolkey_class(unsigned long object_id) {
 1874|     18|	return (object_id >> 24) & 0xff;
 1875|     18|}
card-coolkey.c:coolkey_read_binary:
 1180|     67|{
 1181|     67|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     67|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1182|     67|	int r = 0;
 1183|     67|	size_t len;
 1184|     67|	u8 *data = NULL;
 1185|       |
 1186|     67|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1187|     67|	if (idx > priv->obj->length) {
  ------------------
  |  Branch (1187:6): [True: 0, False: 67]
  ------------------
 1188|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1189|      0|	}
 1190|       |
 1191|       |	/* if we've already read the data, just return it */
 1192|     67|	if (priv->obj->data) {
  ------------------
  |  Branch (1192:6): [True: 51, False: 16]
  ------------------
 1193|     51|		sc_log(card->ctx, "returning cached value idx=%u count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1194|     51|		len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|     51|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 40, False: 11]
  |  |  ------------------
  ------------------
 1195|     51|		memcpy(buf, &priv->obj->data[idx], len);
 1196|     51|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|     51|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     51|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     51|	int _ret = r; \
  |  |  |  |  155|     51|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 51]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     51|	} else { \
  |  |  |  |  159|     51|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     51|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     51|	} \
  |  |  |  |  162|     51|	return _ret; \
  |  |  |  |  163|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1197|     51|	}
 1198|       |
 1199|     16|	sc_log(card->ctx, "clearing cache idx=%u count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1200|       |
 1201|     16|	data = malloc(priv->obj->length);
 1202|     16|	if (data == NULL) {
  ------------------
  |  Branch (1202:6): [True: 0, False: 16]
  ------------------
 1203|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1204|      0|		goto done;
 1205|      0|	}
 1206|       |
 1207|       |
 1208|     16|	r = coolkey_read_object(card, priv->obj->id, 0, data, priv->obj->length,
 1209|     16|		priv->nonce, sizeof(priv->nonce));
 1210|     16|	if (r < 0)
  ------------------
  |  Branch (1210:6): [True: 4, False: 12]
  ------------------
 1211|      4|		goto done;
 1212|       |
 1213|     12|	if ((size_t) r != priv->obj->length) {
  ------------------
  |  Branch (1213:6): [True: 0, False: 12]
  ------------------
 1214|      0|		priv->obj->length = r;
 1215|      0|	}
 1216|       |
 1217|       |
 1218|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
 1219|     12|	len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|     12|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 11, False: 1]
  |  |  ------------------
  ------------------
 1220|     12|	memcpy(buf, &data[idx], len);
 1221|     12|	r = (int)len;
 1222|       |	/* cache the data in the object */
 1223|     12|	priv->obj->data=data;
 1224|     12|	data = NULL;
 1225|       |
 1226|     16|done:
 1227|     16|	if (data)
  ------------------
  |  Branch (1227:6): [True: 4, False: 12]
  ------------------
 1228|      4|		free(data);
 1229|     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: 4, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      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|     12|	} else { \
  |  |  |  |  159|     12|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     12|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     12|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1230|     16|}
card-coolkey.c:coolkey_card_ctl:
 1581|  37.8k|{
 1582|  37.8k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  37.8k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1583|       |
 1584|  37.8k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  37.8k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  37.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  37.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  37.8k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 37.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1585|  37.8k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  37.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__
  |  |  ------------------
  ------------------
 1586|       |
 1587|  37.8k|	if (priv == NULL) {
  ------------------
  |  Branch (1587:6): [True: 0, False: 37.8k]
  ------------------
 1588|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1589|      0|	}
 1590|  37.8k|	switch(cmd) {
  ------------------
  |  Branch (1590:9): [True: 37.8k, False: 0]
  ------------------
 1591|      0|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1591:3): [True: 0, False: 37.8k]
  ------------------
 1592|      0|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1593|    555|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1593:3): [True: 555, False: 37.3k]
  ------------------
 1594|    555|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1595|  1.51k|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1595:3): [True: 1.51k, False: 36.3k]
  ------------------
 1596|  1.51k|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1597|    555|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1597:3): [True: 555, False: 37.3k]
  ------------------
 1598|    555|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1599|  3.58k|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1599:3): [True: 3.58k, False: 34.2k]
  ------------------
 1600|  3.58k|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1601|    555|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1601:3): [True: 555, False: 37.3k]
  ------------------
 1602|    555|			return coolkey_final_iterator(&priv->objects_list);
 1603|  31.1k|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1603:3): [True: 31.1k, False: 6.77k]
  ------------------
 1604|  31.1k|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1605|  37.8k|	}
 1606|       |
 1607|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1608|      0|}
card-coolkey.c:coolkey_get_token_info:
 1326|    555|{
 1327|    555|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    555|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1328|    555|	char *label = NULL;
 1329|    555|	char *manufacturer_id = NULL;
 1330|    555|	char *serial_number = NULL;
 1331|       |
 1332|    555|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    555|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    555|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    555|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    555|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 555]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1333|    555|	label = strdup((char *)priv->token_name);
 1334|    555|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1335|    555|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1336|       |
 1337|    555|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1337:6): [True: 555, False: 0]
  |  Branch (1337:15): [True: 555, False: 0]
  |  Branch (1337:34): [True: 555, False: 0]
  ------------------
 1338|    555|		free(token_info->label);
 1339|    555|		token_info->label = label;
 1340|    555|		free(token_info->manufacturer_id);
 1341|    555|		token_info->manufacturer_id = manufacturer_id;
 1342|    555|		free(token_info->serial_number);
 1343|    555|		token_info->serial_number = serial_number;
 1344|    555|		return SC_SUCCESS;
  ------------------
  |  |   28|    555|#define SC_SUCCESS				0
  ------------------
 1345|    555|	}
 1346|      0|	free(label);
 1347|      0|	free(manufacturer_id);
 1348|      0|	free(serial_number);
 1349|      0|	return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1350|    555|}
card-coolkey.c:coolkey_get_manufacturer:
 1297|    555|{
 1298|    555|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1299|    555|	int i;
 1300|    555|	char *buf;
 1301|    555|	const char *manufacturer_string = "%04x Unknown";
 1302|    555|	size_t len;
 1303|    555|	int r;
 1304|       |
 1305|  3.32k|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1305:12): [True: 2.77k, False: 553]
  ------------------
 1306|  2.77k|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1306:7): [True: 2, False: 2.76k]
  ------------------
 1307|      2|			manufacturer_string = manufacturer_list[i].string;
 1308|      2|			break;
 1309|      2|		}
 1310|  2.77k|	}
 1311|    555|	len = strlen(manufacturer_string)+1;
 1312|    555|	buf= malloc(len);
 1313|    555|	if (buf == NULL) {
  ------------------
  |  Branch (1313:6): [True: 0, False: 555]
  ------------------
 1314|      0|		return NULL;
 1315|      0|	}
 1316|    555|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1317|    555|	if (r < 0) {
  ------------------
  |  Branch (1317:6): [True: 0, False: 555]
  ------------------
 1318|      0|		free(buf);
 1319|      0|		return NULL;
 1320|      0|	}
 1321|    555|	return buf;
 1322|    555|}
card-coolkey.c:coolkey_cuid_to_string:
 1272|    555|{
 1273|    555|	char *buf;
 1274|    555|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1275|    555|	buf = malloc(len);
 1276|    555|	if (buf == NULL) {
  ------------------
  |  Branch (1276:6): [True: 0, False: 555]
  ------------------
 1277|      0|		return NULL;
 1278|      0|	}
 1279|    555|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1280|    555|	return buf;
 1281|    555|}
card-coolkey.c:coolkey_find_object:
 1552|  1.51k|{
 1553|  1.51k|	sc_cardctl_coolkey_object_t *obj = NULL;
 1554|  1.51k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.51k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1555|  1.51k|	int r;
 1556|       |
 1557|  1.51k|	switch (fobj->type) {
 1558|    423|	case SC_CARDCTL_COOLKEY_FIND_BY_ID:
  ------------------
  |  | 1072|    423|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
  |  Branch (1558:2): [True: 423, False: 1.09k]
  ------------------
 1559|    423|		obj = coolkey_find_object_by_id(&priv->objects_list, fobj->find_id);
 1560|    423|		break;
 1561|  1.09k|	case SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE:
  ------------------
  |  | 1073|  1.09k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  |  Branch (1561:2): [True: 1.09k, False: 423]
  ------------------
 1562|  1.09k|		obj = coolkey_find_object_by_template(card, fobj->coolkey_template, fobj->template_count);
 1563|  1.09k|		break;
 1564|      0|	default:
  ------------------
  |  Branch (1564:2): [True: 0, False: 1.51k]
  ------------------
 1565|      0|		break;
 1566|  1.51k|	}
 1567|  1.51k|	if (obj == NULL) {
  ------------------
  |  Branch (1567:6): [True: 904, False: 615]
  ------------------
 1568|    904|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    904|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 1569|    904|	}
 1570|    615|	if (obj->data == NULL) {
  ------------------
  |  Branch (1570:6): [True: 27, False: 588]
  ------------------
 1571|     27|		r = coolkey_fill_object(card, obj);
 1572|     27|		if (r < 0) {
  ------------------
  |  Branch (1572:7): [True: 23, False: 4]
  ------------------
 1573|     23|			return r;
 1574|     23|		}
 1575|     27|	}
 1576|    592|	fobj->obj = obj;
 1577|    592|	return SC_SUCCESS;
  ------------------
  |  |   28|    592|#define SC_SUCCESS				0
  ------------------
 1578|    615|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1245|    555|{
 1246|    555|	*countp = list_size(list);
 1247|    555|	list_iterator_start(list);
 1248|    555|	return SC_SUCCESS;
  ------------------
  |  |   28|    555|#define SC_SUCCESS				0
  ------------------
 1249|    555|}
card-coolkey.c:coolkey_fetch_object:
 1253|  3.58k|{
 1254|  3.58k|	sc_cardctl_coolkey_object_t *ptr;
 1255|  3.58k|	if (!list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1255:6): [True: 0, False: 3.58k]
  ------------------
 1256|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
 1257|      0|	}
 1258|       |
 1259|  3.58k|	ptr = list_iterator_next(list);
 1260|  3.58k|	*coolkey_obj = *ptr;
 1261|  3.58k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.58k|#define SC_SUCCESS				0
  ------------------
 1262|  3.58k|}
card-coolkey.c:coolkey_final_iterator:
 1266|    555|{
 1267|    555|	list_iterator_stop(list);
 1268|    555|	return SC_SUCCESS;
  ------------------
  |  |   28|    555|#define SC_SUCCESS				0
  ------------------
 1269|    555|}
card-coolkey.c:coolkey_check_sw:
  876|  40.0k|{
  877|  40.0k|	sc_log(card->ctx,
  ------------------
  |  |   71|  40.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__
  |  |  ------------------
  ------------------
  878|  40.0k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  879|       |
  880|  40.0k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (880:6): [True: 17.4k, False: 22.6k]
  |  Branch (880:21): [True: 16.9k, False: 543]
  ------------------
  881|  16.9k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.9k|#define SC_SUCCESS				0
  ------------------
  882|       |
  883|  23.1k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (883:6): [True: 88, False: 23.0k]
  ------------------
  884|     88|		if (sw2 == 0xff) {
  ------------------
  |  Branch (884:7): [True: 7, False: 81]
  ------------------
  885|       |			/* shouldn't happen on a production applet, 0x9cff is a debugging error code */
  886|      7|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      7|#define SC_ERROR_INTERNAL			-1400
  ------------------
  887|      7|		}
  888|     81|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (888:7): [True: 27, False: 54]
  ------------------
  889|     27|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     27|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  890|     27|		}
  891|     54|		return coolkey_error_codes[sw2].sc_error;
  892|     81|	}
  893|       |
  894|       |	/* iso error */
  895|  23.0k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  896|  23.1k|}
card-coolkey.c:coolkey_pin_cmd:
 2349|     17|{
 2350|     17|	int r;
 2351|     17|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     17|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2352|     17|	size_t rbuflen;
 2353|     17|	u8 *rbuf;
 2354|       |
 2355|       |	/* COOLKEY uses a separate pin from the card pin, managed by the applet.
 2356|       |	 * if we successfully log into coolkey, we will get a nonce, which we append
 2357|       |	 * to our APDUs to authenticate the apdu to the card. This allows coolkey to
 2358|       |	 * maintain separate per application login states without the application
 2359|       |	 * having to cache the pin */
 2360|     17|	switch (data->cmd) {
 2361|      0|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2361:2): [True: 0, False: 17]
  ------------------
 2362|      0|		if (priv->nonce_valid) {
  ------------------
  |  Branch (2362:7): [True: 0, False: 0]
  ------------------
 2363|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 2364|      0|		} else {
 2365|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 2366|       |			/* coolkey retries is 100. It's unlikely the pin is block.
 2367|       |			 * instead, coolkey slows down the login command exponentially
 2368|       |			 */
 2369|      0|			data->pin1.tries_left = 0xf;
 2370|      0|		}
 2371|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2372|      0|		break;
 2373|       |
 2374|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2374:2): [True: 0, False: 17]
  ------------------
 2375|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2375:2): [True: 0, False: 17]
  ------------------
 2376|       |		/* these 2 commands are currently reserved for TPS */
 2377|      0|	default:
  ------------------
  |  Branch (2377:2): [True: 0, False: 17]
  ------------------
 2378|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2379|      0|		break;
 2380|     17|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     17|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2380:2): [True: 17, False: 0]
  ------------------
 2381|       |		/* coolkey applet supports multiple pins, but TPS currently only uses one.
 2382|       |		 * just support the one pin for now (we need an array of nonces to handle
 2383|       |		 * multiple pins) */
 2384|       |		/* coolkey only supports unpadded ascii pins, so no need to format the pin */
 2385|     17|		rbuflen = sizeof(priv->nonce);
 2386|     17|		rbuf = &priv->nonce[0];
 2387|     17|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   72|     17|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   80|     17|#define COOLKEY_INS_VERIFY_PIN                 0x42
  ------------------
 2388|     17|			data->pin_reference, 0, data->pin1.data, data->pin1.len,
 2389|     17|			&rbuf, &rbuflen, NULL, 0);
 2390|     17|		if (r < 0) {
  ------------------
  |  Branch (2390:7): [True: 15, False: 2]
  ------------------
 2391|     15|			break;
 2392|     15|		}
 2393|      2|		priv->nonce_valid = 1;
 2394|      2|		r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 2395|     17|	}
 2396|     17|	return r;
 2397|     17|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2418|  19.8k|{
 2419|  19.8k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  19.8k|#define SC_SUCCESS				0
  ------------------
 2420|       |
 2421|  19.8k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  19.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  19.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  19.8k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 19.8k]
  |  |  ------------------
  ------------------
 2422|       |
 2423|  19.8k|	if (was_reset > 0) {
  ------------------
  |  Branch (2423:6): [True: 0, False: 19.8k]
  ------------------
 2424|      0|		r = coolkey_select_applet(card);
 2425|      0|	}
 2426|       |
 2427|  19.8k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  19.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  19.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  19.8k|	int _ret = r; \
  |  |  |  |  155|  19.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 19.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  19.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 19.8k]
  |  |  |  |  ------------------
  |  |  |  |  157|  19.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  19.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|  19.8k|	return _ret; \
  |  |  |  |  163|  19.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2428|  19.8k|}

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

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

sc_get_dtrust_driver:
 1056|  14.1k|{
 1057|  14.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1057:6): [True: 1, False: 14.1k]
  ------------------
 1058|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1059|       |
 1060|  14.1k|	dtrust_ops = *iso_ops;
 1061|  14.1k|	dtrust_ops.match_card = dtrust_match_card;
 1062|  14.1k|	dtrust_ops.init = dtrust_init;
 1063|  14.1k|	dtrust_ops.finish = dtrust_finish;
 1064|  14.1k|	dtrust_ops.pin_cmd = dtrust_pin_cmd;
 1065|  14.1k|	dtrust_ops.set_security_env = dtrust_set_security_env;
 1066|  14.1k|	dtrust_ops.compute_signature = dtrust_compute_signature;
 1067|  14.1k|	dtrust_ops.decipher = dtrust_decipher;
 1068|  14.1k|	dtrust_ops.logout = dtrust_logout;
 1069|       |
 1070|  14.1k|	return &dtrust_drv;
 1071|  14.1k|}
card-dtrust.c:dtrust_match_card:
  234|  13.7k|{
  235|  13.7k|	if (_sc_match_atr(card, dtrust_atrs, &card->type) < 0)
  ------------------
  |  Branch (235:6): [True: 13.5k, False: 119]
  ------------------
  236|  13.5k|		return 0;
  237|       |
  238|    119|	if (_dtrust_match_cardos(card) != SC_SUCCESS)
  ------------------
  |  |   28|    119|#define SC_SUCCESS				0
  ------------------
  |  Branch (238:6): [True: 117, False: 2]
  ------------------
  239|    117|		return 0;
  240|       |
  241|      2|	if (_dtrust_match_profile(card) != SC_SUCCESS)
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  |  Branch (241:6): [True: 2, False: 0]
  ------------------
  242|      2|		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|      2|}
card-dtrust.c:_dtrust_match_cardos:
  114|    119|{
  115|    119|	int r;
  116|    119|	size_t prodlen;
  117|    119|	u8 buf[32];
  118|       |
  119|       |	/* check OS version */
  120|    119|	r = sc_get_data(card, 0x0182, buf, 32);
  121|    119|	LOG_TEST_RET(card->ctx, r, "OS version check failed");
  ------------------
  |  |  174|    119|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    119|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    119|	int _ret = (r); \
  |  |  |  |  168|    119|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 46, False: 73]
  |  |  |  |  ------------------
  |  |  |  |  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|    119|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 73]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|     73|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (123:6): [True: 35, False: 38]
  ------------------
  124|     35|		if (r != 2 || buf[0] != 0xc9 || buf[1] != 0x04)
  ------------------
  |  Branch (124:7): [True: 6, False: 29]
  |  Branch (124:17): [True: 8, False: 21]
  |  Branch (124:35): [True: 1, False: 20]
  ------------------
  125|     15|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     15|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  126|     38|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (126:13): [True: 38, False: 0]
  ------------------
  127|     38|		if (r != 2 || buf[0] != 0xcb || buf[1] != 0x01)
  ------------------
  |  Branch (127:7): [True: 8, False: 30]
  |  Branch (127:17): [True: 4, False: 26]
  |  Branch (127:35): [True: 1, False: 25]
  ------------------
  128|     13|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     13|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  129|     38|	}
  130|       |
  131|       |	/* check product name */
  132|     45|	r = sc_get_data(card, 0x0180, buf, 32);
  133|     45|	LOG_TEST_RET(card->ctx, r, "Product name check failed");
  ------------------
  |  |  174|     45|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     45|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     45|	int _ret = (r); \
  |  |  |  |  168|     45|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 42]
  |  |  |  |  ------------------
  |  |  |  |  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|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 42]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  134|       |
  135|     42|	prodlen = (size_t)r;
  136|     42|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (136:6): [True: 18, False: 24]
  ------------------
  137|     18|		if (prodlen != strlen("CardOS V5.4     2019") + 1 || memcmp(buf, "CardOS V5.4     2019", prodlen))
  ------------------
  |  Branch (137:7): [True: 6, False: 12]
  |  Branch (137:56): [True: 11, False: 1]
  ------------------
  138|     17|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     17|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  139|     24|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (139:13): [True: 24, False: 0]
  ------------------
  140|     24|		if (prodlen != strlen("CardOS V6.0 2021") + 1 || memcmp(buf, "CardOS V6.0 2021", prodlen))
  ------------------
  |  Branch (140:7): [True: 8, False: 16]
  |  Branch (140:52): [True: 15, False: 1]
  ------------------
  141|     23|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     23|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  142|     24|	}
  143|       |
  144|      2|	return SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  145|     42|}
card-dtrust.c:_dtrust_match_profile:
  149|      2|{
  150|      2|	sc_path_t cia_path;
  151|      2|	int r;
  152|      2|	u8 buf[SC_MAX_APDU_BUFFER_SIZE];
  153|      2|	size_t slen, plen;
  154|      2|	const u8 *sp, *pp;
  155|      2|	char *name;
  156|       |
  157|      2|	sc_format_path("5032", &cia_path);
  158|      2|	cia_path.aid.len = sizeof(cia_path.aid.value);
  159|      2|	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|      2|	LOG_TEST_RET(card->ctx, r, "Formatting AID failed");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|       |
  162|      2|	r = sc_select_file(card, &cia_path, NULL);
  163|      2|	LOG_TEST_RET(card->ctx, r, "Selecting CIA path 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  14.1k|struct sc_card_driver* sc_get_edo_driver(void) {
  307|  14.1k|	edo_ops = *sc_get_iso7816_driver()->ops;
  308|  14.1k|	edo_ops.match_card = edo_match_card;
  309|  14.1k|	edo_ops.init = edo_init;
  310|  14.1k|	edo_ops.select_file = edo_select_file;
  311|  14.1k|	edo_ops.set_security_env = edo_set_security_env;
  312|  14.1k|	edo_ops.compute_signature = edo_compute_signature;
  313|  14.1k|	edo_ops.logout = edo_logout;
  314|       |
  315|  14.1k|	return &edo_drv;
  316|  14.1k|}
card-edo.c:edo_match_card:
   62|  6.55k|static int edo_match_card(sc_card_t* card) {
   63|  6.55k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.55k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.55k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.55k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.55k]
  |  |  ------------------
  ------------------
   64|  6.55k|	if (_sc_match_atr(card, edo_atrs, &card->type) >= 0) {
  ------------------
  |  Branch (64:6): [True: 0, False: 6.55k]
  ------------------
   65|      0|		sc_log(card->ctx, "ATR recognized as Polish eID card.");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   66|      0|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   67|      0|	}
   68|  6.55k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  6.55k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.55k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.55k|	int _ret = r; \
  |  |  |  |  155|  6.55k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.55k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 6.55k]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.55k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.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|  6.55k|	return _ret; \
  |  |  |  |  163|  6.55k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   69|  6.55k|}

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

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

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

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

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

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

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

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

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

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

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

sc_get_itacns_driver:
  523|  14.1k|{
  524|  14.1k|	return sc_get_driver();
  525|  14.1k|}
card-itacns.c:sc_get_driver:
  504|  14.1k|{
  505|  14.1k|	if (!default_ops)
  ------------------
  |  Branch (505:6): [True: 1, False: 14.1k]
  ------------------
  506|      1|		default_ops = sc_get_iso7816_driver()->ops;
  507|  14.1k|	itacns_ops = *default_ops;
  508|  14.1k|	itacns_ops.match_card = itacns_match_card;
  509|  14.1k|	itacns_ops.init = itacns_init;
  510|  14.1k|	itacns_ops.finish = itacns_finish;
  511|  14.1k|	itacns_ops.set_security_env = itacns_set_security_env;
  512|  14.1k|	itacns_ops.restore_security_env = itacns_restore_security_env;
  513|  14.1k|	itacns_ops.pin_cmd = itacns_pin_cmd;
  514|  14.1k|	itacns_ops.read_binary = itacns_read_binary;
  515|  14.1k|	itacns_ops.list_files = itacns_list_files;
  516|  14.1k|	itacns_ops.select_file = itacns_select_file;
  517|  14.1k|	itacns_ops.card_ctl = itacns_card_ctl;
  518|  14.1k|	itacns_ops.get_challenge = itacns_get_challenge;
  519|  14.1k|	return &itacns_drv;
  520|  14.1k|}
card-itacns.c:itacns_match_card:
  122|  3.61k|{
  123|  3.61k|	int r = 0;
  124|       |
  125|       |	/* Try table first */
  126|  3.61k|	r = _sc_match_atr(card, itacns_atrs, &card->type);
  127|  3.61k|	if(r >= 0) return 1;
  ------------------
  |  Branch (127:5): [True: 174, False: 3.43k]
  ------------------
  128|       |
  129|  3.43k|	if (itacns_match_cns_card(card)) return 1;
  ------------------
  |  Branch (129:6): [True: 56, False: 3.38k]
  ------------------
  130|  3.38k|	if (itacns_match_cie_card(card)) return 1;
  ------------------
  |  Branch (130:6): [True: 3, False: 3.37k]
  ------------------
  131|       |
  132|       |	/* No card type was matched. */
  133|  3.37k|	return 0;
  134|  3.38k|}
card-itacns.c:itacns_match_cns_card:
   85|  3.43k|{
   86|  3.43k|	u8 manufacturer_code;
   87|  3.43k|	u8 manufacturer_mask;
   88|  3.43k|	u8 fw_major;
   89|       |
   90|  3.43k|	if (15 != card->reader->atr_info.hist_bytes_len ||
  ------------------
  |  Branch (90:6): [True: 3.28k, False: 152]
  ------------------
   91|    152|	    0 != memcmp(card->reader->atr_info.hist_bytes+9, "CNS", 3))
  ------------------
  |  Branch (91:6): [True: 96, False: 56]
  ------------------
   92|  3.38k|		return 0;
   93|       |
   94|     56|	card->type = SC_CARD_TYPE_ITACNS_CNS;
   95|       |
   96|     56|	manufacturer_code = card->reader->atr_info.hist_bytes[2];
   97|     56|	manufacturer_mask = card->reader->atr_info.hist_bytes[3];
   98|     56|	fw_major = card->reader->atr_info.hist_bytes[4];
   99|       |
  100|     56|	if (manufacturer_code == ITACNS_ICMAN_INFINEON &&
  ------------------
  |  |    9|    112|#define ITACNS_ICMAN_INFINEON		0x05
  ------------------
  |  Branch (100:6): [True: 6, False: 50]
  ------------------
  101|      6|	    manufacturer_mask == ITACNS_MASKMAN_IDEMIA &&
  ------------------
  |  |   11|     62|#define ITACNS_MASKMAN_IDEMIA		0x05
  ------------------
  |  Branch (101:6): [True: 5, False: 1]
  ------------------
  102|      5|	    fw_major >= 32) {
  ------------------
  |  Branch (102:6): [True: 1, False: 4]
  ------------------
  103|      1|			card->type = SC_CARD_TYPE_ITACNS_CNS_IDEMIA_2021;
  104|      1|	}
  105|       |
  106|     56|	return 1;
  107|  3.43k|}
card-itacns.c:itacns_match_cie_card:
  110|  3.38k|{
  111|  3.38k|	u8 h7_to_h15[] = { 0x02, 'I', 'T', 'I', 'D', 0x20, 0x20, 0x31, 0x80, };
  112|  3.38k|	if (15 != card->reader->atr_info.hist_bytes_len ||
  ------------------
  |  Branch (112:6): [True: 3.28k, False: 96]
  ------------------
  113|     96|	    0 != memcmp(card->reader->atr_info.hist_bytes+6,
  ------------------
  |  Branch (113:6): [True: 93, False: 3]
  ------------------
  114|     96|			h7_to_h15, sizeof h7_to_h15))
  115|  3.37k|		return 0;
  116|       |
  117|      3|	card->type = SC_CARD_TYPE_ITACNS_CIE_V2;
  118|      3|	return 1;
  119|  3.38k|}
card-itacns.c:itacns_init:
  141|    233|{
  142|    233|	unsigned long	flags;
  143|       |
  144|    233|	SC_FUNC_CALLED(card->ctx, 1);
  ------------------
  |  |  148|    233|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    233|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    233|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 233]
  |  |  ------------------
  ------------------
  145|       |
  146|    233|	card->name = "CNS card";
  147|    233|	card->cla = 0x00;
  148|       |
  149|    233|	card->drv_data = calloc(1, sizeof(itacns_drv_data_t));
  150|    233|	if (!card->drv_data)
  ------------------
  |  Branch (150:6): [True: 0, False: 233]
  ------------------
  151|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  152|       |
  153|    233|	if (card->type == SC_CARD_TYPE_ITACNS_CNS)
  ------------------
  |  Branch (153:6): [True: 55, False: 178]
  ------------------
  154|     55|		itacns_init_cns_card(card);
  155|       |
  156|    233|	DRVDATA(card)->ic_manufacturer_code = card->reader->atr_info.hist_bytes[2];
  ------------------
  |  |   64|    233|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
  157|    233|	DRVDATA(card)->mask_manufacturer_code = card->reader->atr_info.hist_bytes[3];
  ------------------
  |  |   64|    233|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
  158|    233|	card->version.fw_major = card->reader->atr_info.hist_bytes[4];
  159|    233|	card->version.fw_minor = card->reader->atr_info.hist_bytes[5];
  160|       |
  161|       |	/* Set up algorithm info. */
  162|    233|	flags = SC_ALGORITHM_NEED_USAGE
  ------------------
  |  |   95|    233|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  163|    233|		| SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|    233|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  164|    233|		| SC_ALGORITHM_RSA_HASHES
  ------------------
  |  |  142|    233|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  165|    233|		;
  166|       |
  167|    233|	if ((card->version.hw_major >= 1 && card->version.hw_minor >= 1) ||
  ------------------
  |  Branch (167:7): [True: 45, False: 188]
  |  Branch (167:38): [True: 40, False: 5]
  ------------------
  168|    193|	    card->type == SC_CARD_TYPE_ITACNS_CNS_IDEMIA_2021) {
  ------------------
  |  Branch (168:6): [True: 3, False: 190]
  ------------------
  169|     43|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     43|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  170|     43|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  171|    190|	} else {
  172|    190|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  173|    190|	}
  174|    233|	return SC_SUCCESS;
  ------------------
  |  |   28|    233|#define SC_SUCCESS				0
  ------------------
  175|    233|}
card-itacns.c:itacns_init_cns_card:
   67|     55|{
   68|     55|	if (15 != card->reader->atr_info.hist_bytes_len)
  ------------------
  |  Branch (68:6): [True: 0, False: 55]
  ------------------
   69|      0|		return;
   70|       |
   71|     55|	u8 cns_version = card->reader->atr_info.hist_bytes[12];
   72|     55|	card->version.hw_major = (cns_version >> 4) & 0x0f;
   73|     55|	card->version.hw_minor = cns_version & 0x0f;
   74|       |
   75|       |	/* Warn if version is not 1.X. */
   76|     55|	if (cns_version != 0x10 && cns_version != 0x11) {
  ------------------
  |  Branch (76:6): [True: 53, False: 2]
  |  Branch (76:29): [True: 52, False: 1]
  ------------------
   77|     52|		char version[8];
   78|     52|		snprintf(version, sizeof(version), "%d.%d", card->version.hw_major, card->version.hw_minor);
   79|     52|		sc_log(card->ctx, "CNS card version %s; no official specifications "
  ------------------
  |  |   71|     52|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   80|     52|		       "are published. Proceeding anyway.\n", version);
   81|     52|	}
   82|     55|}
card-itacns.c:itacns_finish:
  178|    233|{
  179|    233|	if(card->drv_data) {
  ------------------
  |  Branch (179:5): [True: 233, False: 0]
  ------------------
  180|    233|		free(card->drv_data);
  181|    233|	}
  182|    233|	return 0;
  183|    233|}
card-itacns.c:itacns_pin_cmd:
  297|     10|{
  298|     10|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     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|    944|{
  317|    944|	size_t already_read = 0;
  318|    944|	size_t requested;
  319|    944|	int r;
  320|  1.04k|	while(1) {
  ------------------
  |  Branch (320:8): [True: 1.04k, Folded]
  ------------------
  321|  1.04k|		requested = count - already_read;
  322|  1.04k|		if(requested > ITACNS_MAX_PAYLOAD)
  ------------------
  |  |   36|  1.04k|#define ITACNS_MAX_PAYLOAD 0xff
  ------------------
  |  Branch (322:6): [True: 613, False: 436]
  ------------------
  323|    613|			requested = ITACNS_MAX_PAYLOAD;
  ------------------
  |  |   36|    613|#define ITACNS_MAX_PAYLOAD 0xff
  ------------------
  324|  1.04k|		r = default_ops->read_binary(card, (unsigned)(idx + already_read),
  325|  1.04k|			&buf[already_read], requested, flags);
  326|  1.04k|		if(r < 0)
  ------------------
  |  Branch (326:6): [True: 142, False: 907]
  ------------------
  327|    142|			return r;
  328|    907|		already_read += r;
  329|    907|		if (r == 0 || (size_t)r < requested || already_read == count) {
  ------------------
  |  Branch (329:7): [True: 64, False: 843]
  |  Branch (329:17): [True: 519, False: 324]
  |  Branch (329:42): [True: 219, False: 105]
  ------------------
  330|       |			/* We have finished */
  331|    802|			return (int)already_read;
  332|    802|		}
  333|    907|	}
  334|    944|}
card-itacns.c:itacns_select_file:
  421|  1.93k|{
  422|  1.93k|	int r;
  423|       |
  424|  1.93k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.93k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.93k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.93k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.93k]
  |  |  ------------------
  ------------------
  425|  1.93k|	r = default_ops->select_file(card, in_path, file);
  426|  1.93k|	if (r >= 0 && file) {
  ------------------
  |  Branch (426:6): [True: 601, False: 1.33k]
  |  Branch (426:16): [True: 185, False: 416]
  ------------------
  427|    185|		parse_sec_attr((*file), (*file)->sec_attr,
  428|    185|			(*file)->sec_attr_len);
  429|    185|	}
  430|  1.93k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.93k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.93k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.93k|	int _ret = r; \
  |  |  |  |  155|  1.93k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.93k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.93k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.33k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.33k, False: 601]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.93k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.93k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.93k|	return _ret; \
  |  |  |  |  163|  1.93k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|  1.93k|}
card-itacns.c:parse_sec_attr:
  403|    185|{
  404|    185|	size_t i;
  405|    185|	const int *idx;
  406|       |
  407|    185|	idx = (file->type == SC_FILE_TYPE_DF) ?  df_acl : ef_acl;
  ------------------
  |  |  214|    185|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (407:8): [True: 4, False: 181]
  ------------------
  408|       |
  409|       |	/* acl defaults to 0xFF if unspecified */
  410|  1.85k|	for (i = 0; i < 9; i++) {
  ------------------
  |  Branch (410:14): [True: 1.66k, False: 185]
  ------------------
  411|  1.66k|		if (idx[i] != -1) {
  ------------------
  |  Branch (411:7): [True: 1.29k, False: 370]
  ------------------
  412|  1.29k|			add_acl_entry(file, idx[i],
  413|  1.29k|				(u8)((i < len) ? buf[i] : 0xFF));
  ------------------
  |  Branch (413:10): [True: 150, False: 1.14k]
  ------------------
  414|  1.29k|		}
  415|  1.66k|	}
  416|    185|}
card-itacns.c:add_acl_entry:
  350|  1.29k|{
  351|  1.29k|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  1.29k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  352|       |
  353|  1.29k|	switch (byte) {
  354|     32|	case 0x00:
  ------------------
  |  Branch (354:2): [True: 32, False: 1.26k]
  ------------------
  355|     32|		method = SC_AC_NONE;
  ------------------
  |  |  150|     32|#define SC_AC_NONE			0x00000000
  ------------------
  356|     32|		break;
  357|  1.15k|	case 0xFF:
  ------------------
  |  Branch (357:2): [True: 1.15k, False: 144]
  ------------------
  358|  1.17k|	case 0x66:
  ------------------
  |  Branch (358:2): [True: 20, False: 1.27k]
  ------------------
  359|  1.17k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.17k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  360|  1.17k|		break;
  361|     92|	default:
  ------------------
  |  Branch (361:2): [True: 92, False: 1.20k]
  ------------------
  362|     92|		if (byte > 0x1F) {
  ------------------
  |  Branch (362:7): [True: 59, False: 33]
  ------------------
  363|     59|			method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     59|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  364|     59|		} else {
  365|     33|			method = SC_AC_CHV;
  ------------------
  |  |  151|     33|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  366|     33|			key_ref = byte;
  367|     33|		}
  368|     92|		break;
  369|  1.29k|	}
  370|  1.29k|	sc_file_add_acl_entry(file, op, method, key_ref);
  371|  1.29k|}
card-itacns.c:itacns_card_ctl:
  486|    384|{
  487|    384|	switch (cmd) {
  ------------------
  |  Branch (487:10): [True: 10, False: 374]
  ------------------
  488|     10|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (488:3): [True: 10, False: 374]
  ------------------
  489|     10|		return itacns_get_serialnr(card, ptr);
  490|    384|	}
  491|    374|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    374|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  492|    384|}
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: 3, False: 7]
  ------------------
  455|      3|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      3|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  456|      3|	}
  457|      7|	len = file->size;
  458|      7|	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|      7|	if (len != 16) {
  ------------------
  |  Branch (464:6): [True: 6, False: 1]
  ------------------
  465|      6|		sc_log(card->ctx,
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  466|      6|				"Unexpected file length of EF_IDCarta (%lu)\n",
  467|      6|				(unsigned long) len);
  468|      6|	}
  469|       |
  470|      7|	r = sc_read_binary(card, 0, rbuf, 256, 0);
  471|      7|	if ( r != 16 ) {
  ------------------
  |  Branch (471:7): [True: 6, False: 1]
  ------------------
  472|      6|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      6|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  473|      6|	}
  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|      7|}

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

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

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

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

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

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

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

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

sc_get_oberthur_driver:
 2319|  14.1k|{
 2320|  14.1k|	return sc_get_driver();
 2321|  14.1k|}
card-oberthur.c:sc_get_driver:
 2288|  14.1k|{
 2289|  14.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2289:6): [True: 1, False: 14.1k]
  ------------------
 2290|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2291|       |
 2292|  14.1k|	auth_ops = *iso_ops;
 2293|  14.1k|	auth_ops.match_card = auth_match_card;
 2294|  14.1k|	auth_ops.init = auth_init;
 2295|  14.1k|	auth_ops.finish = auth_finish;
 2296|  14.1k|	auth_ops.select_file = auth_select_file;
 2297|  14.1k|	auth_ops.list_files = auth_list_files;
 2298|  14.1k|	auth_ops.delete_file = auth_delete_file;
 2299|  14.1k|	auth_ops.create_file = auth_create_file;
 2300|  14.1k|	auth_ops.read_binary = auth_read_binary;
 2301|  14.1k|	auth_ops.update_binary = auth_update_binary;
 2302|  14.1k|	auth_ops.read_record = auth_read_record;
 2303|  14.1k|	auth_ops.delete_record = auth_delete_record;
 2304|  14.1k|	auth_ops.card_ctl = auth_card_ctl;
 2305|  14.1k|	auth_ops.set_security_env = auth_set_security_env;
 2306|  14.1k|	auth_ops.restore_security_env = auth_restore_security_env;
 2307|  14.1k|	auth_ops.compute_signature = auth_compute_signature;
 2308|  14.1k|	auth_ops.decipher = auth_decipher;
 2309|  14.1k|	auth_ops.process_fci = auth_process_fci;
 2310|  14.1k|	auth_ops.pin_cmd = auth_pin_cmd;
 2311|  14.1k|	auth_ops.logout = auth_logout;
 2312|  14.1k|	auth_ops.check_sw = auth_check_sw;
 2313|  14.1k|	return &auth_drv;
 2314|  14.1k|}
card-oberthur.c:auth_match_card:
  204|  10.8k|{
  205|  10.8k|	if (_sc_match_atr(card, oberthur_atrs, &card->type) < 0)
  ------------------
  |  Branch (205:6): [True: 10.0k, False: 744]
  ------------------
  206|  10.0k|		return 0;
  207|    744|	else
  208|    744|		return 1;
  209|  10.8k|}
card-oberthur.c:auth_init:
  214|    744|{
  215|    744|	struct auth_private_data *data;
  216|    744|	struct sc_path path;
  217|    744|	unsigned long flags;
  218|    744|	int rv = 0;
  219|       |
  220|    744|	data = calloc(1, sizeof(struct auth_private_data));
  221|    744|	if (!data)
  ------------------
  |  Branch (221:6): [True: 0, False: 744]
  ------------------
  222|    744|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_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|    744|	card->cla = 0x00;
  225|    744|	card->drv_data = data;
  226|       |
  227|    744|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    744|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  228|    744|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    744|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  229|       |
  230|    744|	if (auth_select_aid(card)) {
  ------------------
  |  Branch (230:6): [True: 37, False: 707]
  ------------------
  231|     37|		sc_log(card->ctx, "Failed to initialize %s", card->name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  232|     37|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     37|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  233|     37|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to initialize");
  ------------------
  |  |  184|     37|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     37|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     37|	int _ret = (r); \
  |  |  |  |  178|     37|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 37, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     37|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     37|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     37|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     37|		goto err; \
  |  |  |  |  182|     37|	} \
  |  |  |  |  183|     37|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     37|	}
  235|       |
  236|    707|	sc_format_path("3F00", &path);
  237|    707|	rv = auth_select_file(card, &path, NULL);
  238|       |
  239|    744|err:
  240|    744|	if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|    744|#define SC_SUCCESS				0
  ------------------
  |  Branch (240:6): [True: 707, False: 37]
  ------------------
  241|    707|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  111|    707|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    707|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    707|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  106|    707|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  242|    707|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    707|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|    707|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    707|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  244|       |
  245|    707|		_sc_card_add_rsa_alg(card, 512, flags, 0);
  246|    707|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  247|    707|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  248|    707|	} else {
  249|     37|		free(card->drv_data);
  250|     37|		card->drv_data = NULL;
  251|     37|	}
  252|       |
  253|    744|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    744|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    744|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    744|	int _ret = r; \
  |  |  |  |  155|    744|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 744, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    744|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 707]
  |  |  |  |  ------------------
  |  |  |  |  157|    744|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    744|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    744|	return _ret; \
  |  |  |  |  163|    744|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|    744|}
card-oberthur.c:auth_select_aid:
  145|    744|{
  146|    744|	struct sc_apdu apdu;
  147|    744|	unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  148|    744|	struct auth_private_data *data = (struct auth_private_data *)card->drv_data;
  149|    744|	int rv, ii;
  150|    744|	struct sc_path tmp_path;
  151|       |
  152|       |	/* Select Card Manager (to deselect previously selected application) */
  153|    744|	rv = gp_select_card_manager(card);
  154|    744|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    744|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    744|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    744|	int _ret = (r); \
  |  |  |  |  168|    744|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 22, False: 722]
  |  |  |  |  ------------------
  |  |  |  |  169|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     22|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     22|		return _ret; \
  |  |  |  |  172|     22|	} \
  |  |  |  |  173|    744|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 722]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	/* Get smart card serial number */
  157|    722|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x9F, 0x7F);
  ------------------
  |  |  292|    722|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  158|    722|	apdu.cla = 0x80;
  159|    722|	apdu.le = 0x2D;
  160|    722|	apdu.resplen = 0x30;
  161|    722|	apdu.resp = apdu_resp;
  162|       |
  163|    722|	rv = sc_transmit_apdu(card, &apdu);
  164|    722|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    722|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    722|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    722|	int _ret = (r); \
  |  |  |  |  168|    722|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 718]
  |  |  |  |  ------------------
  |  |  |  |  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|    722|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 718]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|    718|	if (apdu.resplen < 20) {
  ------------------
  |  Branch (165:6): [True: 4, False: 714]
  ------------------
  166|      4|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Serial number has incorrect length");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|      4|	}
  168|    714|	card->serialnr.len = 4;
  169|    714|	memcpy(card->serialnr.value, apdu.resp+15, 4);
  170|       |
  171|  3.57k|	for (ii=0, data->sn = 0; ii < 4; ii++)
  ------------------
  |  Branch (171:27): [True: 2.85k, False: 714]
  ------------------
  172|  2.85k|		data->sn += (long int)(*(apdu.resp + 15 + ii)) << (3-ii)*8;
  173|       |
  174|    714|	sc_log(card->ctx, "serial number %li/0x%lX", data->sn, data->sn);
  ------------------
  |  |   71|    714|#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|    714|	memset(&tmp_path, 0, sizeof(struct sc_path));
  177|    714|	tmp_path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    714|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  178|    714|	memcpy(tmp_path.value, aidAuthentIC_V5, lenAidAuthentIC_V5);
  179|    714|	tmp_path.len = lenAidAuthentIC_V5;
  180|       |
  181|    714|	rv = iso_ops->select_file(card, &tmp_path, NULL);
  182|    714|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    714|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    714|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    714|	int _ret = (r); \
  |  |  |  |  168|    714|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 709]
  |  |  |  |  ------------------
  |  |  |  |  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|    714|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 709]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|    709|	sc_format_path("3F00", &tmp_path);
  185|    709|	sc_file_free(auth_current_df);
  186|    709|	auth_current_df = NULL;
  187|    709|	rv = iso_ops->select_file(card, &tmp_path, &auth_current_df);
  188|    709|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    709|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    709|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    709|	int _ret = (r); \
  |  |  |  |  168|    709|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 707]
  |  |  |  |  ------------------
  |  |  |  |  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|    709|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 707]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|       |
  190|    707|	sc_file_free(auth_current_ef);
  191|    707|	auth_current_ef = NULL;
  192|    707|	sc_file_dup(&auth_current_ef, auth_current_df);
  193|       |
  194|    707|	memcpy(data->aid, aidAuthentIC_V5, lenAidAuthentIC_V5);
  195|    707|	data->aid_len = lenAidAuthentIC_V5;
  196|    707|	card->name = nameAidAuthentIC_V5;
  197|       |
  198|    707|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    707|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 707]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|    707|}
card-oberthur.c:auth_finish:
  137|    707|{
  138|    707|	free(card->drv_data);
  139|    707|	return SC_SUCCESS;
  ------------------
  |  |   28|    707|#define SC_SUCCESS				0
  ------------------
  140|    707|}
card-oberthur.c:auth_select_file:
  443|  11.8k|{
  444|  11.8k|	struct sc_path path;
  445|  11.8k|	struct sc_file *tmp_file = NULL;
  446|  11.8k|	size_t offs, ii;
  447|  11.8k|	int rv;
  448|       |
  449|  11.8k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (449:6): [True: 0, False: 11.8k]
  |  Branch (449:22): [True: 0, False: 11.8k]
  ------------------
  450|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  451|       |
  452|  11.8k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  11.8k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.8k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  453|       |
  454|  11.8k|	memcpy(&path, in_path, sizeof(struct sc_path));
  455|       |
  456|  11.8k|	if (!auth_current_df)
  ------------------
  |  Branch (456:6): [True: 0, False: 11.8k]
  ------------------
  457|      0|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  458|       |
  459|  11.8k|	sc_log(card->ctx, "in_path; type=%d, path=%s, out %p",
  ------------------
  |  |   71|  11.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  460|  11.8k|			in_path->type, sc_print_path(in_path), file_out);
  461|  11.8k|	sc_log(card->ctx, "current path; type=%d, path=%s",
  ------------------
  |  |   71|  11.8k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  462|  11.8k|			auth_current_df->path.type, sc_print_path(&auth_current_df->path));
  463|  11.8k|	if (auth_current_ef)
  ------------------
  |  Branch (463:6): [True: 7.06k, False: 4.76k]
  ------------------
  464|  7.06k|		sc_log(card->ctx, "current file; type=%d, path=%s",
  ------------------
  |  |   71|  7.06k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  465|  11.8k|				auth_current_ef->path.type, sc_print_path(&auth_current_ef->path));
  466|       |
  467|  11.8k|	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  123|  23.6k|#define SC_PATH_TYPE_PARENT		5
  ------------------
              	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  117|  11.7k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (467:6): [True: 98, False: 11.7k]
  |  Branch (467:42): [True: 5.53k, False: 6.19k]
  ------------------
  468|  5.63k|		sc_file_free(auth_current_ef);
  469|  5.63k|		auth_current_ef = NULL;
  470|       |
  471|  5.63k|		rv = iso_ops->select_file(card, &path, &tmp_file);
  472|  5.63k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  5.63k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.63k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.63k|	int _ret = (r); \
  |  |  |  |  168|  5.63k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.16k, False: 3.46k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.16k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.16k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.16k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.16k|		return _ret; \
  |  |  |  |  172|  2.16k|	} \
  |  |  |  |  173|  5.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.46k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  473|  3.46k|		if (!tmp_file)
  ------------------
  |  Branch (473:7): [True: 0, False: 3.46k]
  ------------------
  474|      0|			return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  475|       |
  476|  3.46k|		if (path.type == SC_PATH_TYPE_PARENT) {
  ------------------
  |  |  123|  3.46k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (476:7): [True: 49, False: 3.42k]
  ------------------
  477|     49|			memcpy(&tmp_file->path, &auth_current_df->path, sizeof(struct sc_path));
  478|     49|			if (tmp_file->path.len > 2)
  ------------------
  |  Branch (478:8): [True: 49, False: 0]
  ------------------
  479|     49|				tmp_file->path.len -= 2;
  480|       |
  481|     49|			sc_file_free(auth_current_df);
  482|     49|			auth_current_df = NULL;
  483|     49|			sc_file_dup(&auth_current_df, tmp_file);
  484|  3.42k|		} else {
  485|  3.42k|			if (tmp_file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  3.42k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (485:8): [True: 91, False: 3.32k]
  ------------------
  486|     91|				sc_concatenate_path(&tmp_file->path, &auth_current_df->path, &path);
  487|       |
  488|     91|				sc_file_free(auth_current_df);
  489|     91|				auth_current_df = NULL;
  490|     91|				sc_file_dup(&auth_current_df, tmp_file);
  491|  3.32k|			} else {
  492|  3.32k|				sc_file_free(auth_current_ef);
  493|  3.32k|				auth_current_ef = NULL;
  494|       |
  495|  3.32k|				sc_file_dup(&auth_current_ef, tmp_file);
  496|  3.32k|				sc_concatenate_path(&auth_current_ef->path, &auth_current_df->path, &path);
  497|  3.32k|			}
  498|  3.42k|		}
  499|  3.46k|		if (file_out) {
  ------------------
  |  Branch (499:7): [True: 2.91k, False: 552]
  ------------------
  500|  2.91k|			sc_file_free(*file_out);
  501|  2.91k|			sc_file_dup(file_out, tmp_file);
  502|  2.91k|		}
  503|       |
  504|  3.46k|		sc_file_free(tmp_file);
  505|  6.19k|	} else if (path.type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  6.19k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (505:13): [True: 1.34k, False: 4.85k]
  ------------------
  506|  1.34k|		rv = iso_ops->select_file(card, &path, NULL);
  507|  1.34k|		if (rv) {
  ------------------
  |  Branch (507:7): [True: 1.30k, False: 43]
  ------------------
  508|  1.30k|			sc_file_free(auth_current_ef);
  509|  1.30k|			auth_current_ef = NULL;
  510|  1.30k|		}
  511|  1.34k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  1.34k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.34k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.34k|	int _ret = (r); \
  |  |  |  |  168|  1.34k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.30k, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  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.34k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 43]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  512|  4.85k|	} else {
  513|  9.70k|		for (offs = 0; offs < path.len && offs < auth_current_df->path.len; offs += 2)
  ------------------
  |  Branch (513:18): [True: 9.00k, False: 707]
  |  Branch (513:37): [True: 4.98k, False: 4.01k]
  ------------------
  514|  4.98k|			if (path.value[offs] != auth_current_df->path.value[offs] ||
  ------------------
  |  Branch (514:8): [True: 100, False: 4.88k]
  ------------------
  515|  4.88k|					path.value[offs + 1] != auth_current_df->path.value[offs + 1])
  ------------------
  |  Branch (515:6): [True: 26, False: 4.85k]
  ------------------
  516|    126|				break;
  517|       |
  518|  4.85k|		sc_log(card->ctx, "offs %zu", offs);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
  519|  4.85k|		if (offs && offs < auth_current_df->path.len) {
  ------------------
  |  Branch (519:7): [True: 4.81k, False: 34]
  |  Branch (519:15): [True: 92, False: 4.72k]
  ------------------
  520|     92|			size_t deep = auth_current_df->path.len - offs;
  521|       |
  522|     92|			sc_log(card->ctx, "deep %zu", deep);
  ------------------
  |  |   71|     92|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  523|    141|			for (ii = 0; ii < deep; ii += 2) {
  ------------------
  |  Branch (523:17): [True: 98, False: 43]
  ------------------
  524|     98|				struct sc_path tmp_path;
  525|       |
  526|     98|				memcpy(&tmp_path, &auth_current_df->path,  sizeof(struct sc_path));
  527|     98|				tmp_path.type = SC_PATH_TYPE_PARENT;
  ------------------
  |  |  123|     98|#define SC_PATH_TYPE_PARENT		5
  ------------------
  528|       |
  529|     98|				if (file_out) {
  ------------------
  |  Branch (529:9): [True: 23, False: 75]
  ------------------
  530|     23|					sc_file_free(*file_out);
  531|     23|					*file_out = NULL;
  532|     23|				}
  533|       |
  534|     98|				rv = auth_select_file (card, &tmp_path, file_out);
  535|     98|				LOG_TEST_RET(card->ctx, rv, "select file 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: 49, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  169|     49|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     49|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     49|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     49|		return _ret; \
  |  |  |  |  172|     49|	} \
  |  |  |  |  173|     98|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 49]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|     98|			}
  537|     92|		}
  538|       |
  539|  4.80k|		if (path.len > offs) {
  ------------------
  |  Branch (539:7): [True: 4.09k, False: 707]
  ------------------
  540|  4.09k|			struct sc_path tmp_path;
  541|       |
  542|  4.09k|			memset(&tmp_path, 0, sizeof(struct sc_path));
  543|  4.09k|			tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  4.09k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  544|  4.09k|			tmp_path.len = 2;
  545|       |
  546|  7.51k|			for (ii = 0; ii < path.len - offs; ii += 2) {
  ------------------
  |  Branch (546:17): [True: 5.53k, False: 1.97k]
  ------------------
  547|  5.53k|				memcpy(tmp_path.value, path.value + offs + ii, 2);
  548|       |
  549|  5.53k|				if (file_out) {
  ------------------
  |  Branch (549:9): [True: 4.17k, False: 1.36k]
  ------------------
  550|  4.17k|					sc_file_free(*file_out);
  551|  4.17k|					*file_out = NULL;
  552|  4.17k|				}
  553|       |
  554|  5.53k|				rv = auth_select_file(card, &tmp_path, file_out);
  555|  5.53k|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  5.53k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.53k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.53k|	int _ret = (r); \
  |  |  |  |  168|  5.53k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.11k, False: 3.42k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.11k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.11k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.11k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.11k|		return _ret; \
  |  |  |  |  172|  2.11k|	} \
  |  |  |  |  173|  5.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.42k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|  5.53k|			}
  557|  4.09k|		} else if (path.len - offs == 0 && file_out) {
  ------------------
  |  Branch (557:14): [True: 707, False: 0]
  |  Branch (557:38): [True: 0, False: 707]
  ------------------
  558|      0|			if (sc_compare_path(&path, &auth_current_df->path) && file_out) {
  ------------------
  |  Branch (558:8): [True: 0, False: 0]
  |  Branch (558:58): [True: 0, False: 0]
  ------------------
  559|      0|				sc_file_free(*file_out);
  560|      0|				sc_file_dup(file_out, auth_current_df);
  561|      0|			} else  if (auth_current_ef && file_out) {
  ------------------
  |  Branch (561:16): [True: 0, False: 0]
  |  Branch (561:35): [True: 0, False: 0]
  ------------------
  562|      0|				sc_file_free(*file_out);
  563|      0|				sc_file_dup(file_out, auth_current_ef);
  564|      0|			} else {
  565|      0|				LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL, "No current EF");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|      0|			}
  567|      0|		}
  568|  4.80k|	}
  569|       |
  570|  6.19k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  6.19k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.19k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.19k|	int _ret = r; \
  |  |  |  |  155|  6.19k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.19k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.19k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 6.19k]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.19k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.19k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  6.19k|	return _ret; \
  |  |  |  |  163|  6.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|  6.19k|}
card-oberthur.c:auth_read_binary:
 2102|  9.92k|{
 2103|  9.92k|	int rv;
 2104|  9.92k|	size_t sz;
 2105|  9.92k|	struct sc_pkcs15_bignum bn[2];
 2106|  9.92k|	unsigned char *out = NULL;
 2107|  9.92k|	bn[0].data = NULL;
 2108|  9.92k|	bn[1].data = NULL;
 2109|       |
 2110|  9.92k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  9.92k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.92k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.92k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.92k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.92k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2111|       |
 2112|  9.92k|	if (!auth_current_ef)
  ------------------
  |  Branch (2112:6): [True: 18, False: 9.90k]
  ------------------
 2113|  9.92k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid auth_current_ef");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2114|       |
 2115|  9.90k|	sc_log(card->ctx, "offset %i; size %zu; flags 0x%lX", offset, count, flags ? *flags : 0);
  ------------------
  |  |   71|  19.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 9.90k]
  |  |  ------------------
  ------------------
 2116|  9.90k|	sc_log(card->ctx, "last selected : magic %X; ef %X",
  ------------------
  |  |   71|  9.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__
  |  |  ------------------
  ------------------
 2117|  9.90k|			auth_current_ef->magic, auth_current_ef->ef_structure);
 2118|       |
 2119|  9.90k|	if (offset & ~0x7FFF)
  ------------------
  |  Branch (2119:6): [True: 1, False: 9.90k]
  ------------------
 2120|  9.90k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2121|       |
 2122|  9.90k|	if (auth_current_ef->magic == SC_FILE_MAGIC &&
  ------------------
  |  |   57|  19.8k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  |  Branch (2122:6): [True: 9.90k, False: 0]
  ------------------
 2123|  9.90k|			auth_current_ef->ef_structure == SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC) {
  ------------------
  |  Branch (2123:4): [True: 181, False: 9.72k]
  ------------------
 2124|    181|		int jj;
 2125|    181|		unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 2126|    181|		size_t resp_len, out_len;
 2127|    181|		struct sc_pkcs15_pubkey_rsa key;
 2128|       |
 2129|    181|		resp_len = sizeof(resp);
 2130|    181|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2131|    181|				2, resp, resp_len);
 2132|    181|		LOG_TEST_RET(card->ctx, rv, "read component failed");
  ------------------
  |  |  174|    181|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    181|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    181|	int _ret = (r); \
  |  |  |  |  168|    181|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 40, False: 141]
  |  |  |  |  ------------------
  |  |  |  |  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|    181|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 141]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2133|       |
 2134|    366|		for (jj=0; jj<rv && *(resp+jj)==0; jj++)
  ------------------
  |  Branch (2134:14): [True: 352, False: 14]
  |  Branch (2134:23): [True: 225, False: 127]
  ------------------
 2135|    225|			;
 2136|       |
 2137|    141|		if (rv - jj == 0)
  ------------------
  |  Branch (2137:7): [True: 14, False: 127]
  ------------------
 2138|     14|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     14|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2139|    127|		bn[0].data = calloc(1, rv - jj);
 2140|    127|		if (!bn[0].data) {
  ------------------
  |  Branch (2140:7): [True: 0, False: 127]
  ------------------
 2141|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2142|      0|			goto err;
 2143|      0|		}
 2144|    127|		bn[0].len = rv - jj;
 2145|    127|		memcpy(bn[0].data, resp + jj, rv - jj);
 2146|       |
 2147|    127|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2148|    127|				1, resp, resp_len);
 2149|    127|		LOG_TEST_GOTO_ERR(card->ctx, rv, "Cannot read RSA public key component");
  ------------------
  |  |  184|    127|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    127|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    127|	int _ret = (r); \
  |  |  |  |  178|    127|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 16, False: 111]
  |  |  |  |  ------------------
  |  |  |  |  179|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     16|		goto err; \
  |  |  |  |  182|     16|	} \
  |  |  |  |  183|    127|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 111]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2150|       |
 2151|    111|		bn[1].data = calloc(1, rv);
 2152|    111|		if (!bn[1].data) {
  ------------------
  |  Branch (2152:7): [True: 0, False: 111]
  ------------------
 2153|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2154|      0|			goto err;
 2155|      0|		}
 2156|    111|		bn[1].len = rv;
 2157|    111|		memcpy(bn[1].data, resp, rv);
 2158|       |
 2159|    111|		key.exponent = bn[0];
 2160|    111|		key.modulus = bn[1];
 2161|       |
 2162|    111|		if (sc_pkcs15_encode_pubkey_rsa(card->ctx, &key, &out, &out_len) != SC_SUCCESS) {
  ------------------
  |  |   28|    111|#define SC_SUCCESS				0
  ------------------
  |  Branch (2162:7): [True: 3, False: 108]
  ------------------
 2163|      3|			rv = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2164|      3|			LOG_TEST_GOTO_ERR(card->ctx, rv, "cannot encode RSA public key");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2165|      3|		}
 2166|    108|		else {
 2167|    108|			if (out_len < offset) {
  ------------------
  |  Branch (2167:8): [True: 8, False: 100]
  ------------------
 2168|      8|				rv = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      8|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 2169|      8|				goto err;
 2170|      8|			}
 2171|    100|			sz = MIN(out_len - offset, count);
  ------------------
  |  |   70|    100|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 76, False: 24]
  |  |  ------------------
  ------------------
 2172|    100|			memcpy(buf, out + offset, sz);
 2173|       |
 2174|    100|			sc_log_hex(card->ctx, "write_publickey", buf, sz);
  ------------------
  |  |  129|    100|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    100|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2175|    100|			rv = (int)sz;
 2176|    100|		}
 2177|  9.72k|	} else {
 2178|  9.72k|		rv = iso_ops->read_binary(card, offset, buf, count, 0);
 2179|  9.72k|	}
 2180|       |
 2181|  9.85k|err:
 2182|  9.85k|	free(bn[0].data);
 2183|  9.85k|	free(bn[1].data);
 2184|  9.85k|	free(out);
 2185|       |
 2186|  9.85k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  9.85k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.85k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.85k|	int _ret = r; \
  |  |  |  |  155|  9.85k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 844, False: 9.00k]
  |  |  |  |  ------------------
  |  |  |  |  156|    844|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    826|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 826, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  157|    844|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.00k|	} else { \
  |  |  |  |  159|  9.00k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  9.00k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  9.00k|	} \
  |  |  |  |  162|  9.85k|	return _ret; \
  |  |  |  |  163|  9.85k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2187|  9.85k|}
card-oberthur.c:auth_read_component:
 1463|    308|{
 1464|    308|	struct sc_apdu apdu;
 1465|    308|	int rv;
 1466|    308|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 1467|       |
 1468|    308|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1469|    308|	sc_log(card->ctx, "num %i, outlen %zu, type %i", num, outlen, type);
  ------------------
  |  |   71|    308|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1470|       |
 1471|    308|	if (!outlen || type!=SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC)
  ------------------
  |  Branch (1471:6): [True: 0, False: 308]
  |  Branch (1471:17): [True: 0, False: 308]
  ------------------
 1472|    308|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1473|       |
 1474|    308|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB4,	num, 0x00);
  ------------------
  |  |  292|    308|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1475|    308|	apdu.cla |= 0x80;
 1476|    308|	apdu.le = outlen;
 1477|    308|	apdu.resp = resp;
 1478|    308|	apdu.resplen = sizeof(resp);
 1479|    308|	rv = sc_transmit_apdu(card, &apdu);
 1480|    308|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    308|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    308|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    308|	int _ret = (r); \
  |  |  |  |  168|    308|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 303]
  |  |  |  |  ------------------
  |  |  |  |  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|    308|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 303]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1481|       |
 1482|    303|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1483|    303|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  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: 51, False: 252]
  |  |  |  |  ------------------
  |  |  |  |  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|    303|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 252]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1484|       |
 1485|    252|	if (outlen < apdu.resplen)
  ------------------
  |  Branch (1485:6): [True: 0, False: 252]
  ------------------
 1486|    252|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1487|       |
 1488|    252|	memcpy(out, apdu.resp, apdu.resplen);
 1489|    252|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    252|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    252|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    252|	int _ret = r; \
  |  |  |  |  155|    252|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 241]
  |  |  |  |  ------------------
  |  |  |  |  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|    241|	} else { \
  |  |  |  |  159|    241|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    241|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    241|	} \
  |  |  |  |  162|    252|	return _ret; \
  |  |  |  |  163|    252|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1490|    252|}
card-oberthur.c:auth_read_record:
 2193|    436|{
 2194|    436|	struct sc_apdu apdu;
 2195|    436|	int rv = 0;
 2196|    436|	unsigned char recvbuf[SC_MAX_APDU_BUFFER_SIZE];
 2197|       |
 2198|    436|	sc_log(card->ctx, "auth_read_record(): nr_rec %i; count %zu", nr_rec, count);
  ------------------
  |  |   71|    436|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2199|       |
 2200|    436|	if (nr_rec > 0xFF || idx != 0)
  ------------------
  |  Branch (2200:6): [True: 0, False: 436]
  |  Branch (2200:23): [True: 70, False: 366]
  ------------------
 2201|    436|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2202|       |
 2203|    366|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB2, nr_rec, 0);
  ------------------
  |  |  292|    366|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 2204|    366|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|    366|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
 2205|    366|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|    366|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (2205:6): [True: 366, False: 0]
  ------------------
 2206|    366|		apdu.p2 |= 0x04;
 2207|       |
 2208|    366|	apdu.le = MIN(count, SC_MAX_APDU_BUFFER_SIZE);
  ------------------
  |  |   70|    366|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 366, False: 0]
  |  |  ------------------
  ------------------
 2209|    366|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    366|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 2210|    366|	apdu.resp = recvbuf;
 2211|       |
 2212|    366|	rv = sc_transmit_apdu(card, &apdu);
 2213|    366|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    366|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    366|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    366|	int _ret = (r); \
  |  |  |  |  168|    366|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 358]
  |  |  |  |  ------------------
  |  |  |  |  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|    366|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 358]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2214|    358|	if (apdu.resplen == 0)
  ------------------
  |  Branch (2214:6): [True: 100, False: 258]
  ------------------
 2215|    358|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|    100|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    100|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    100|	int _ret = r; \
  |  |  |  |  155|    100|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 100, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    100|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 51, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2216|    258|	if (count < apdu.resplen)
  ------------------
  |  Branch (2216:6): [True: 3, False: 255]
  ------------------
 2217|    258|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2218|    255|	memcpy(buf, recvbuf, apdu.resplen);
 2219|       |
 2220|    255|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2221|    255|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    255|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    255|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    255|	int _ret = (r); \
  |  |  |  |  168|    255|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 245]
  |  |  |  |  ------------------
  |  |  |  |  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|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 245]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2222|       |
 2223|    245|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 0, False: 245]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    245|	} else { \
  |  |  |  |  159|    245|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    245|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    245|	} \
  |  |  |  |  162|    245|	return _ret; \
  |  |  |  |  163|    245|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2224|    245|}
card-oberthur.c:auth_card_ctl:
 1435|      4|{
 1436|      4|	switch (cmd) {
 1437|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1437:2): [True: 0, False: 4]
  ------------------
 1438|      0|		return auth_get_default_key(card,
 1439|      0|				(struct sc_cardctl_default_key *) ptr);
 1440|      0|	case SC_CARDCTL_OBERTHUR_GENERATE_KEY:
  ------------------
  |  Branch (1440:2): [True: 0, False: 4]
  ------------------
 1441|      0|		return auth_generate_key(card, 0,
 1442|      0|				(struct sc_cardctl_oberthur_genkey_info *) ptr);
 1443|      0|	case SC_CARDCTL_OBERTHUR_UPDATE_KEY:
  ------------------
  |  Branch (1443:2): [True: 0, False: 4]
  ------------------
 1444|      0|		return auth_update_key(card,
 1445|      0|				(struct sc_cardctl_oberthur_updatekey_info *) ptr);
 1446|      0|	case SC_CARDCTL_OBERTHUR_CREATE_PIN:
  ------------------
  |  Branch (1446:2): [True: 0, False: 4]
  ------------------
 1447|      0|		return auth_create_reference_data(card,
 1448|      0|				(struct sc_cardctl_oberthur_createpin_info *) ptr);
 1449|      4|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1449:2): [True: 4, False: 0]
  ------------------
 1450|      4|		return auth_get_serialnr(card, (struct sc_serial_number *)ptr);
 1451|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1451:2): [True: 0, False: 4]
  ------------------
 1452|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1452:2): [True: 0, False: 4]
  ------------------
 1453|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1454|      0|	default:
  ------------------
  |  Branch (1454:2): [True: 0, False: 4]
  ------------------
 1455|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1456|      4|	}
 1457|      4|}
card-oberthur.c:auth_init_pin_info:
 1521|    765|{
 1522|    765|	pin->offset = 0;
 1523|    765|	pin->pad_char   = 0xFF;
 1524|    765|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    765|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1525|       |
 1526|    765|	if (type == OBERTHUR_AUTH_TYPE_PIN) {
  ------------------
  |  |   92|    765|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
  |  Branch (1526:6): [True: 765, False: 0]
  ------------------
 1527|    765|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|    765|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1528|    765|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|    765|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1529|    765|	} else {
 1530|      0|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1531|      0|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1532|      0|	}
 1533|    765|}
card-oberthur.c:auth_get_serialnr:
 2249|      4|{
 2250|      4|	if (!serial)
  ------------------
  |  Branch (2250:6): [True: 0, False: 4]
  ------------------
 2251|      4|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2252|       |
 2253|      4|	if (card->serialnr.len==0)
  ------------------
  |  Branch (2253:6): [True: 0, False: 4]
  ------------------
 2254|      4|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2255|       |
 2256|      4|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2257|       |
 2258|      4|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2259|      4|}
card-oberthur.c:auth_process_fci:
  297|  2.91k|{
  298|  2.91k|	unsigned char type;
  299|  2.91k|	const unsigned char *attr;
  300|  2.91k|	size_t attr_len = 0;
  301|       |
  302|  2.91k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.91k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.91k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.91k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.91k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.91k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|  2.91k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  304|  2.91k|	if (!attr || attr_len < 1)
  ------------------
  |  Branch (304:6): [True: 1.34k, False: 1.56k]
  |  Branch (304:15): [True: 26, False: 1.53k]
  ------------------
  305|  2.91k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.37k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.37k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.37k|	int _ret = r; \
  |  |  |  |  155|  1.37k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.37k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|  1.37k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.37k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.37k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.37k|	return _ret; \
  |  |  |  |  163|  1.37k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  306|  1.53k|	type = attr[0];
  307|       |
  308|  1.53k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x83, &attr_len);
  309|  1.53k|	if (!attr || attr_len < 2)
  ------------------
  |  Branch (309:6): [True: 16, False: 1.52k]
  |  Branch (309:15): [True: 12, False: 1.50k]
  ------------------
  310|  1.53k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  311|  1.50k|	file->id = attr[0]*0x100 + attr[1];
  312|       |
  313|  1.50k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, type==0x01 ? 0x80 : 0x85, &attr_len);
  ------------------
  |  Branch (313:50): [True: 838, False: 671]
  ------------------
  314|  1.50k|	switch (type) {
  315|    838|	case 0x01:
  ------------------
  |  Branch (315:2): [True: 838, False: 671]
  ------------------
  316|    838|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (316:7): [True: 13, False: 825]
  |  Branch (316:16): [True: 11, False: 814]
  ------------------
  317|    838|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     24|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     24|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     24|	int _ret = r; \
  |  |  |  |  155|     24|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     24|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     24|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     24|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     24|	return _ret; \
  |  |  |  |  163|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|    814|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    814|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  319|    814|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    814|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  320|    814|		file->size = attr[0]*0x100 + attr[1];
  321|    814|		break;
  322|    156|	case 0x04:
  ------------------
  |  Branch (322:2): [True: 156, False: 1.35k]
  ------------------
  323|    156|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (323:7): [True: 11, False: 145]
  |  Branch (323:16): [True: 10, False: 135]
  ------------------
  324|    156|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|    135|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    135|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  326|    135|		file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|    135|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  327|    135|		file->size = attr[0];
  328|    135|		attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  329|    135|		if (!attr || attr_len < 5)
  ------------------
  |  Branch (329:7): [True: 0, False: 135]
  |  Branch (329:16): [True: 33, False: 102]
  ------------------
  330|    135|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     33|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     33|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     33|	int _ret = r; \
  |  |  |  |  155|     33|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     33|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     33|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     33|	return _ret; \
  |  |  |  |  163|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  331|    102|		file->record_length = attr[2]*0x100+attr[3];
  332|    102|		file->record_count = attr[4];
  333|    102|		break;
  334|     90|	case 0x11:
  ------------------
  |  Branch (334:2): [True: 90, False: 1.41k]
  ------------------
  335|     90|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (335:7): [True: 10, False: 80]
  |  Branch (335:16): [True: 11, False: 69]
  ------------------
  336|     90|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     21|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     21|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     21|	int _ret = r; \
  |  |  |  |  155|     21|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 21, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     21|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|     69|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     69|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  338|     69|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_DES;
  339|     69|		file->size = attr[0]*0x100 + attr[1];
  340|     69|		file->size /= 8;
  341|     69|		break;
  342|    183|	case 0x12:
  ------------------
  |  Branch (342:2): [True: 183, False: 1.32k]
  ------------------
  343|    183|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (343:7): [True: 12, False: 171]
  |  Branch (343:16): [True: 11, False: 160]
  ------------------
  344|    183|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  345|    160|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    160|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  346|    160|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC;
  347|       |
  348|    160|		file->size = attr[0]*0x100 + attr[1];
  349|    160|		if (file->size==512)
  ------------------
  |  Branch (349:7): [True: 23, False: 137]
  ------------------
  350|     23|			file->size = PUBKEY_512_ASN1_SIZE;
  ------------------
  |  |  100|     23|#define PUBKEY_512_ASN1_SIZE	0x4A
  ------------------
  351|    137|		else if (file->size==1024)
  ------------------
  |  Branch (351:12): [True: 20, False: 117]
  ------------------
  352|     20|			file->size = PUBKEY_1024_ASN1_SIZE;
  ------------------
  |  |  101|     20|#define PUBKEY_1024_ASN1_SIZE	0x8C
  ------------------
  353|    117|		else if (file->size==2048)
  ------------------
  |  Branch (353:12): [True: 0, False: 117]
  ------------------
  354|      0|			file->size = PUBKEY_2048_ASN1_SIZE;
  ------------------
  |  |  102|      0|#define PUBKEY_2048_ASN1_SIZE	0x10E
  ------------------
  355|    117|		else {
  356|    117|			sc_log(card->ctx, "Not supported public key size: %zu", file->size);
  ------------------
  |  |   71|    117|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  357|    117|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    117|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    117|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    117|	int _ret = r; \
  |  |  |  |  155|    117|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 117, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    117|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    117|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 117, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    117|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    117|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    117|	return _ret; \
  |  |  |  |  163|    117|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|    117|		}
  359|     43|		break;
  360|     43|	case 0x14:
  ------------------
  |  Branch (360:2): [True: 31, False: 1.47k]
  ------------------
  361|     31|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (361:7): [True: 10, False: 21]
  |  Branch (361:16): [True: 10, False: 11]
  ------------------
  362|     31|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|     11|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     11|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  364|     11|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_CRT;
  365|     11|		file->size = attr[0]*0x100 + attr[1];
  366|     11|		break;
  367|    187|	case 0x38:
  ------------------
  |  Branch (367:2): [True: 187, False: 1.32k]
  ------------------
  368|    187|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (368:7): [True: 23, False: 164]
  |  Branch (368:16): [True: 13, False: 151]
  ------------------
  369|    187|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  370|    151|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    151|#define SC_FILE_TYPE_DF			0x04
  ------------------
  371|    151|		file->size = attr[0];
  372|    151|		if (SC_SUCCESS != sc_file_set_type_attr(file,attr,attr_len))
  ------------------
  |  |   28|    151|#define SC_SUCCESS				0
  ------------------
  |  Branch (372:7): [True: 0, False: 151]
  ------------------
  373|    151|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  374|    151|		break;
  375|    151|	default:
  ------------------
  |  Branch (375:2): [True: 24, False: 1.48k]
  ------------------
  376|     24|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     24|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     24|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     24|	int _ret = r; \
  |  |  |  |  155|     24|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     24|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     24|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     24|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     24|	return _ret; \
  |  |  |  |  163|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|  1.50k|	}
  378|       |
  379|  1.19k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x86, &attr_len);
  380|  1.19k|	if (!attr || attr_len < 8)
  ------------------
  |  Branch (380:6): [True: 932, False: 258]
  |  Branch (380:15): [True: 13, False: 245]
  ------------------
  381|  1.19k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    945|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    945|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    945|	int _ret = r; \
  |  |  |  |  155|    945|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 945, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    945|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    945|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 945, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    945|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    945|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    945|	return _ret; \
  |  |  |  |  163|    945|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|    245|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|    245|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (383:6): [True: 135, False: 110]
  ------------------
  384|    135|		add_acl_entry(card, file, SC_AC_OP_CREATE, attr[0]);
  ------------------
  |  |  169|    135|#define SC_AC_OP_CREATE			3
  ------------------
  385|    135|		add_acl_entry(card, file, SC_AC_OP_CRYPTO, attr[1]);
  ------------------
  |  |  173|    135|#define SC_AC_OP_CRYPTO			7
  ------------------
  386|    135|		add_acl_entry(card, file, SC_AC_OP_LIST_FILES, attr[2]);
  ------------------
  |  |  172|    135|#define SC_AC_OP_LIST_FILES		6
  ------------------
  387|    135|		add_acl_entry(card, file, SC_AC_OP_DELETE, attr[3]);
  ------------------
  |  |  168|    135|#define SC_AC_OP_DELETE			2
  ------------------
  388|    135|		add_acl_entry(card, file, SC_AC_OP_PIN_DEFINE, attr[4]);
  ------------------
  |  |  183|    135|#define SC_AC_OP_PIN_DEFINE		17
  ------------------
  389|    135|		add_acl_entry(card, file, SC_AC_OP_PIN_CHANGE, attr[5]);
  ------------------
  |  |  184|    135|#define SC_AC_OP_PIN_CHANGE		18
  ------------------
  390|    135|		add_acl_entry(card, file, SC_AC_OP_PIN_RESET, attr[6]);
  ------------------
  |  |  185|    135|#define SC_AC_OP_PIN_RESET		19
  ------------------
  391|    135|		sc_log(card->ctx, "SC_FILE_TYPE_DF:CRYPTO %X", attr[1]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  392|    135|	} else if (file->type == SC_FILE_TYPE_INTERNAL_EF) { /* EF */
  ------------------
  |  |  215|    110|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (392:13): [True: 87, False: 23]
  ------------------
  393|     87|		switch (file->ef_structure) {
  ------------------
  |  Branch (393:11): [True: 87, False: 0]
  ------------------
  394|     56|		case SC_CARDCTL_OBERTHUR_KEY_DES:
  ------------------
  |  Branch (394:3): [True: 56, False: 31]
  ------------------
  395|     56|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     56|#define SC_AC_OP_UPDATE			23
  ------------------
  396|     56|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     56|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  397|     56|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     56|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  398|     56|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_CHECKSUM, attr[3]);
  ------------------
  |  |  179|     56|#define SC_AC_OP_PSO_COMPUTE_CHECKSUM	13
  ------------------
  399|     56|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_CHECKSUM, attr[4]);
  ------------------
  |  |  180|     56|#define SC_AC_OP_PSO_VERIFY_CHECKSUM	14
  ------------------
  400|     56|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     56|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  401|     56|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     56|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  402|     56|			break;
  403|     21|		case SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC:
  ------------------
  |  Branch (403:3): [True: 21, False: 66]
  ------------------
  404|     21|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     21|#define SC_AC_OP_UPDATE			23
  ------------------
  405|     21|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     21|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  406|     21|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_SIGNATURE, attr[4]);
  ------------------
  |  |  178|     21|#define SC_AC_OP_PSO_VERIFY_SIGNATURE	12
  ------------------
  407|     21|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     21|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  408|     21|			break;
  409|     10|		case SC_CARDCTL_OBERTHUR_KEY_RSA_CRT:
  ------------------
  |  Branch (409:3): [True: 10, False: 77]
  ------------------
  410|     10|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     10|#define SC_AC_OP_UPDATE			23
  ------------------
  411|     10|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     10|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  412|     10|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_SIGNATURE, attr[3]);
  ------------------
  |  |  177|     10|#define SC_AC_OP_PSO_COMPUTE_SIGNATURE	11
  ------------------
  413|     10|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     10|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  414|     10|			break;
  415|     87|		}
  416|     87|	} else {
  417|     23|		switch (file->ef_structure) {
  ------------------
  |  Branch (417:11): [True: 23, False: 0]
  ------------------
  418|     10|		case SC_FILE_EF_TRANSPARENT:
  ------------------
  |  |  221|     10|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (418:3): [True: 10, False: 13]
  ------------------
  419|     10|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     10|#define SC_AC_OP_WRITE			24
  ------------------
  420|     10|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     10|#define SC_AC_OP_UPDATE			23
  ------------------
  421|     10|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     10|#define SC_AC_OP_READ			22
  ------------------
  422|     10|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     10|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     10|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  423|     10|			break;
  424|     13|		case SC_FILE_EF_LINEAR_VARIABLE:
  ------------------
  |  |  224|     13|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (424:3): [True: 13, False: 10]
  ------------------
  425|     13|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     13|#define SC_AC_OP_WRITE			24
  ------------------
  426|     13|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     13|#define SC_AC_OP_UPDATE			23
  ------------------
  427|     13|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     13|#define SC_AC_OP_READ			22
  ------------------
  428|     13|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     13|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     13|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  429|     13|			break;
  430|     23|		}
  431|     23|	}
  432|       |
  433|    245|	file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    245|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  434|    245|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    245|#define SC_FILE_MAGIC			0x14426950
  ------------------
  435|       |
  436|    245|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|    245|}
card-oberthur.c:add_acl_entry:
  260|  1.55k|{
  261|  1.55k|	if ((acl_byte & 0xE0) == 0x60) {
  ------------------
  |  Branch (261:6): [True: 212, False: 1.34k]
  ------------------
  262|    212|		sc_log(card->ctx, "called; op 0x%X; SC_AC_PRO; ref 0x%X", op, acl_byte);
  ------------------
  |  |   71|    212|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  263|    212|		sc_file_add_acl_entry(file, op, SC_AC_PRO, acl_byte);
  ------------------
  |  |  153|    212|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  264|    212|		return;
  265|    212|	}
  266|       |
  267|  1.34k|	switch (acl_byte) {
  268|    186|	case 0x00:
  ------------------
  |  Branch (268:2): [True: 186, False: 1.15k]
  ------------------
  269|    186|		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    186|#define SC_AC_NONE			0x00000000
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    186|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  270|    186|		break;
  271|       |	/* User and OneTime PINs are locals */
  272|     41|	case 0x21:
  ------------------
  |  Branch (272:2): [True: 41, False: 1.30k]
  ------------------
  273|     94|	case 0x22:
  ------------------
  |  Branch (273:2): [True: 53, False: 1.28k]
  ------------------
  274|     94|		sc_file_add_acl_entry(file, op, SC_AC_CHV, (acl_byte & 0x0F) | OBERTHUR_PIN_LOCAL);
  ------------------
  |  |  151|     94|#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|     94|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
  275|     94|		break;
  276|       |	/* Local SOPIN is only for the unblocking. */
  277|    151|	case 0x24:
  ------------------
  |  Branch (277:2): [True: 151, False: 1.19k]
  ------------------
  278|    273|	case 0x25:
  ------------------
  |  Branch (278:2): [True: 122, False: 1.21k]
  ------------------
  279|    273|		if (op == SC_AC_OP_PIN_RESET)
  ------------------
  |  |  185|    273|#define SC_AC_OP_PIN_RESET		19
  ------------------
  |  Branch (279:7): [True: 49, False: 224]
  ------------------
  280|     49|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x84);
  ------------------
  |  |  151|     49|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  281|    224|		else
  282|    224|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x04);
  ------------------
  |  |  151|    224|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  283|    273|		break;
  284|    154|	case 0xFF:
  ------------------
  |  Branch (284:2): [True: 154, False: 1.18k]
  ------------------
  285|    154|		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|    154|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    154|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  286|    154|		break;
  287|    634|	default:
  ------------------
  |  Branch (287:2): [True: 634, False: 707]
  ------------------
  288|    634|		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|    634|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    634|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  289|    634|		break;
  290|  1.34k|	}
  291|  1.34k|}
card-oberthur.c:auth_pin_cmd:
 1875|    769|{
 1876|    769|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    769|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1877|       |
 1878|    769|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    769|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    769|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    769|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    769|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 769]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1879|    769|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    769|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1879:6): [True: 0, False: 769]
  ------------------
 1880|    769|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "auth_pin_cmd() unsupported PIN type");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1881|       |
 1882|    769|	sc_log(card->ctx, "PIN CMD:%i; reference:%i; pin1:%p/%zu, pin2:%p/%zu", data->cmd,
  ------------------
  |  |   71|    769|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1883|    769|			data->pin_reference, data->pin1.data, data->pin1.len,
 1884|    769|			data->pin2.data, data->pin2.len);
 1885|    769|	switch (data->cmd) {
 1886|    765|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|    765|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1886:2): [True: 765, False: 4]
  ------------------
 1887|    765|		rv = auth_pin_verify(card, SC_AC_CHV, data);
  ------------------
  |  |  151|    765|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1888|    765|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|    765|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    765|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    765|	int _ret = (r); \
  |  |  |  |  168|    765|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 67, False: 698]
  |  |  |  |  ------------------
  |  |  |  |  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|    765|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 698]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1889|    698|		break;
 1890|    698|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1890:2): [True: 0, False: 769]
  ------------------
 1891|      0|		rv = auth_pin_change(card, SC_AC_CHV, data);
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1892|      0|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1893|      0|		break;
 1894|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1894:2): [True: 0, False: 769]
  ------------------
 1895|      0|		rv = auth_pin_reset(card, SC_AC_CHV, data);
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1896|      0|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1897|      0|		break;
 1898|      4|	default:
  ------------------
  |  Branch (1898:2): [True: 4, False: 765]
  ------------------
 1899|      4|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported PIN operation");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1900|    769|	}
 1901|       |
 1902|    698|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    698|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    698|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    698|	int _ret = r; \
  |  |  |  |  155|    698|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 698, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    698|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 698]
  |  |  |  |  ------------------
  |  |  |  |  157|    698|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    698|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    698|	return _ret; \
  |  |  |  |  163|    698|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1903|    698|}
card-oberthur.c:auth_pin_verify:
 1595|    765|{
 1596|    765|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1597|    765|	int rv;
 1598|       |
 1599|    765|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    765|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    765|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    765|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    765|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 765]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1600|       |
 1601|    765|	if (type != SC_AC_CHV)
  ------------------
  |  |  151|    765|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1601:6): [True: 0, False: 765]
  ------------------
 1602|    765|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "PIN type other then SC_AC_CHV is not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1603|       |
 1604|    765|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    765|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1605|       |
 1606|    765|	auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|    765|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1607|       |
 1608|       |	/* User PIN is always local. */
 1609|    765|	if (data->pin_reference == OBERTHUR_PIN_REFERENCE_USER
  ------------------
  |  |   42|  1.53k|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1609:6): [True: 359, False: 406]
  ------------------
 1610|    406|			|| data->pin_reference == OBERTHUR_PIN_REFERENCE_ONETIME)
  ------------------
  |  |   43|    406|#define OBERTHUR_PIN_REFERENCE_ONETIME	0x82
  ------------------
  |  Branch (1610:7): [True: 0, False: 406]
  ------------------
 1611|    359|		data->pin_reference  |= OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|    359|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1612|       |
 1613|    765|        rv = auth_pin_is_verified(card, data->pin_reference, &data->pin1.tries_left);
 1614|    765|    	sc_log(card->ctx, "auth_pin_is_verified returned rv %i", rv);
  ------------------
  |  |   71|    765|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1615|       |
 1616|       |	/* Return if only PIN status has been asked. */
 1617|    765|	if (data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1617:6): [True: 765, False: 0]
  |  Branch (1617:25): [True: 765, False: 0]
  ------------------
 1618|    765|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    765|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    765|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    765|	int _ret = r; \
  |  |  |  |  155|    765|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 765, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    765|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     67|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 67, False: 698]
  |  |  |  |  ------------------
  |  |  |  |  157|    765|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    765|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    765|	return _ret; \
  |  |  |  |  163|    765|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|       |
 1620|       |	/* Return SUCCESS without verifying if
 1621|       |	 * PIN has been already verified and PIN pad has to be used. */
 1622|      0|	if (!rv && !data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1622:6): [True: 0, False: 0]
  |  Branch (1622:13): [True: 0, False: 0]
  |  Branch (1622:33): [True: 0, False: 0]
  ------------------
 1623|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1624|       |
 1625|      0|	if (!data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1625:6): [True: 0, False: 0]
  |  Branch (1625:26): [True: 0, False: 0]
  ------------------
 1626|      0|		rv = auth_pin_verify_pinpad(card, data->pin_reference, &data->pin1.tries_left);
 1627|      0|	else
 1628|      0|		rv = iso_drv->ops->pin_cmd(card, data);
 1629|       |
 1630|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1631|      0|}
card-oberthur.c:auth_pin_is_verified:
 1636|    765|{
 1637|    765|	struct sc_apdu apdu;
 1638|    765|	int rv;
 1639|       |
 1640|    765|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_reference);
  ------------------
  |  |  291|    765|#define SC_APDU_CASE_1			0x01
  ------------------
 1641|       |
 1642|    765|	rv = sc_transmit_apdu(card, &apdu);
 1643|    765|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    765|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    765|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    765|	int _ret = (r); \
  |  |  |  |  168|    765|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 760]
  |  |  |  |  ------------------
  |  |  |  |  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|    765|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 760]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1644|       |
 1645|    760|	if (tries_left && apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)
  ------------------
  |  Branch (1645:6): [True: 760, False: 0]
  |  Branch (1645:20): [True: 19, False: 741]
  |  Branch (1645:40): [True: 15, False: 4]
  ------------------
 1646|     15|		*tries_left = apdu.sw2 & 0x0F;
 1647|       |
 1648|       |	/* Replace 'no tries left' with 'auth method blocked' */
 1649|    760|	if (apdu.sw1 == 0x63 && apdu.sw2 == 0xC0) {
  ------------------
  |  Branch (1649:6): [True: 19, False: 741]
  |  Branch (1649:26): [True: 5, False: 14]
  ------------------
 1650|      5|		apdu.sw1 = 0x69;
 1651|      5|		apdu.sw2 = 0x83;
 1652|      5|	}
 1653|       |
 1654|    760|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1655|       |
 1656|    760|	return rv;
 1657|    765|}
card-oberthur.c:auth_check_sw:
 2272|  20.3k|{
 2273|  20.3k|	int ii;
 2274|       |
 2275|  40.2k|	for (ii = 0; auth_warnings[ii].SWs; ii++) {
  ------------------
  |  Branch (2275:15): [True: 20.3k, False: 19.9k]
  ------------------
 2276|  20.3k|		if (auth_warnings[ii].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (2276:7): [True: 432, False: 19.9k]
  ------------------
 2277|    432|			sc_log(card->ctx, "%s", auth_warnings[ii].errorstr);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2278|    432|			return auth_warnings[ii].errorno;
 2279|    432|		}
 2280|  20.3k|	}
 2281|       |
 2282|  19.9k|	return iso_ops->check_sw(card, sw1, sw2);
 2283|  20.3k|}

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

sc_get_piv_driver:
 6570|  14.1k|{
 6571|  14.1k|	return sc_get_driver();
 6572|  14.1k|}
card-piv.c:sc_get_driver:
 6543|  14.1k|{
 6544|  14.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6545|       |
 6546|  14.1k|	piv_ops = *iso_drv->ops;
 6547|  14.1k|	piv_ops.match_card = piv_match_card;
 6548|  14.1k|	piv_ops.init = piv_init;
 6549|  14.1k|	piv_ops.finish = piv_finish;
 6550|       |
 6551|  14.1k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6552|  14.1k|	piv_ops.get_challenge = piv_get_challenge;
 6553|  14.1k|	piv_ops.logout = piv_logout;
 6554|  14.1k|	piv_ops.read_binary = piv_read_binary;
 6555|  14.1k|	piv_ops.write_binary = piv_write_binary;
 6556|  14.1k|	piv_ops.set_security_env = piv_set_security_env;
 6557|  14.1k|	piv_ops.restore_security_env = piv_restore_security_env;
 6558|  14.1k|	piv_ops.compute_signature = piv_compute_signature;
 6559|  14.1k|	piv_ops.decipher = piv_decipher;
 6560|  14.1k|	piv_ops.check_sw = piv_check_sw;
 6561|  14.1k|	piv_ops.card_ctl = piv_card_ctl;
 6562|  14.1k|	piv_ops.pin_cmd = piv_pin_cmd;
 6563|  14.1k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6564|       |
 6565|  14.1k|	return &piv_drv;
 6566|  14.1k|}
card-piv.c:piv_match_card:
 5508|  5.02k|{
 5509|  5.02k|	int r = 0;
 5510|       |
 5511|  5.02k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  5.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5512|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5513|       |	/* user provided card type must be one we know */
 5514|  5.02k|	switch (card->type) {
 5515|  5.02k|	case -1:
  ------------------
  |  Branch (5515:2): [True: 5.02k, False: 0]
  ------------------
 5516|  5.02k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5516:2): [True: 0, False: 5.02k]
  ------------------
 5517|  5.02k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5517:2): [True: 0, False: 5.02k]
  ------------------
 5518|  5.02k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5518:2): [True: 0, False: 5.02k]
  ------------------
 5519|  5.02k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5519:2): [True: 0, False: 5.02k]
  ------------------
 5520|  5.02k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5520:2): [True: 0, False: 5.02k]
  ------------------
 5521|  5.02k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5521:2): [True: 0, False: 5.02k]
  ------------------
 5522|  5.02k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5522:2): [True: 0, False: 5.02k]
  ------------------
 5523|  5.02k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5523:2): [True: 0, False: 5.02k]
  ------------------
 5524|  5.02k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5524:2): [True: 0, False: 5.02k]
  ------------------
 5525|  5.02k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5525:2): [True: 0, False: 5.02k]
  ------------------
 5526|  5.02k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5526:2): [True: 0, False: 5.02k]
  ------------------
 5527|  5.02k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5527:2): [True: 0, False: 5.02k]
  ------------------
 5528|  5.02k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5528:2): [True: 0, False: 5.02k]
  ------------------
 5529|  5.02k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5529:2): [True: 0, False: 5.02k]
  ------------------
 5530|  5.02k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5530:2): [True: 0, False: 5.02k]
  ------------------
 5531|  5.02k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5531:2): [True: 0, False: 5.02k]
  ------------------
 5532|  5.02k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5532:2): [True: 0, False: 5.02k]
  ------------------
 5533|  5.02k|		break;
 5534|      0|	default:
  ------------------
  |  Branch (5534:2): [True: 0, False: 5.02k]
  ------------------
 5535|      0|		return 0; /* can not handle the card */
 5536|  5.02k|	}
 5537|       |
 5538|  5.02k|	r = sc_lock(card);
 5539|  5.02k|	if (r < 0)
  ------------------
  |  Branch (5539:6): [True: 0, False: 5.02k]
  ------------------
 5540|      0|		return 0;
 5541|       |	/* its one we know, or we can test for it in piv_init */
 5542|  5.02k|	r = piv_match_card_continued(card);
 5543|  5.02k|	sc_unlock(card);
 5544|       |
 5545|  5.02k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5545:6): [True: 4.29k, False: 724]
  |  Branch (5545:15): [True: 0, False: 724]
  ------------------
 5546|       |		/* clean up what we left in card */
 5547|  4.29k|		piv_finish(card);
 5548|  4.29k|		return 0; /* match failed */
 5549|  4.29k|	}
 5550|       |
 5551|    724|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|    724|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5552|    724|	return 1; /* matched */
 5553|  5.02k|}
card-piv.c:piv_match_card_continued:
 5557|  5.02k|{
 5558|  5.02k|	int i, r = 0, r2 = 0;
 5559|  5.02k|	int type = -1;
 5560|  5.02k|	piv_private_data_t *priv = NULL;
 5561|  5.02k|	int saved_type = card->type;
 5562|  5.02k|	sc_apdu_t apdu;
 5563|  5.02k|	u8 yubico_version_buf[3] = {0};
 5564|       |
 5565|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5566|       |	/* User provided card type must be one we know */
 5567|       |
 5568|  5.02k|	switch (card->type) {
 5569|  5.02k|	case -1:
  ------------------
  |  Branch (5569:2): [True: 5.02k, False: 0]
  ------------------
 5570|  5.02k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5570:2): [True: 0, False: 5.02k]
  ------------------
 5571|  5.02k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5571:2): [True: 0, False: 5.02k]
  ------------------
 5572|  5.02k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5572:2): [True: 0, False: 5.02k]
  ------------------
 5573|  5.02k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5573:2): [True: 0, False: 5.02k]
  ------------------
 5574|  5.02k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5574:2): [True: 0, False: 5.02k]
  ------------------
 5575|  5.02k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5575:2): [True: 0, False: 5.02k]
  ------------------
 5576|  5.02k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5576:2): [True: 0, False: 5.02k]
  ------------------
 5577|  5.02k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5577:2): [True: 0, False: 5.02k]
  ------------------
 5578|  5.02k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5578:2): [True: 0, False: 5.02k]
  ------------------
 5579|  5.02k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5579:2): [True: 0, False: 5.02k]
  ------------------
 5580|  5.02k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5580:2): [True: 0, False: 5.02k]
  ------------------
 5581|  5.02k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5581:2): [True: 0, False: 5.02k]
  ------------------
 5582|  5.02k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5582:2): [True: 0, False: 5.02k]
  ------------------
 5583|  5.02k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5583:2): [True: 0, False: 5.02k]
  ------------------
 5584|  5.02k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5584:2): [True: 0, False: 5.02k]
  ------------------
 5585|  5.02k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5585:2): [True: 0, False: 5.02k]
  ------------------
 5586|  5.02k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5586:2): [True: 0, False: 5.02k]
  ------------------
 5587|  5.02k|		type = card->type;
 5588|  5.02k|		break;
 5589|      0|	default:
  ------------------
  |  Branch (5589:2): [True: 0, False: 5.02k]
  ------------------
 5590|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5591|  5.02k|	}
 5592|  5.02k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5593|  5.02k|	if (type == -1) {
  ------------------
  |  Branch (5593:6): [True: 5.02k, False: 0]
  ------------------
 5594|       |		/*
 5595|       |		 * Try to identify card by ATR or historical data in ATR
 5596|       |		 * currently all PIV card will respond to piv_find_aid
 5597|       |		 * the same. But in future may need to know card type first,
 5598|       |		 * so do it here.
 5599|       |		 */
 5600|       |
 5601|  5.02k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5601:7): [True: 1.15k, False: 3.87k]
  ------------------
 5602|  1.15k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5602:8): [True: 90, False: 1.06k]
  ------------------
 5603|     90|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5603:6): [True: 26, False: 64]
  ------------------
 5604|     26|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5605|  1.12k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5605:15): [True: 630, False: 496]
  ------------------
 5606|    630|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5606:6): [True: 85, False: 545]
  ------------------
 5607|     85|				type = SC_CARD_TYPE_PIV_II_NEO;
 5608|  1.04k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5608:15): [True: 597, False: 444]
  ------------------
 5609|    597|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5609:6): [True: 33, False: 564]
  ------------------
 5610|     33|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5611|  1.00k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5611:15): [True: 564, False: 444]
  ------------------
 5612|    564|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5612:6): [True: 7, False: 557]
  ------------------
 5613|      7|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5614|      7|			}
 5615|       |			/* look for TLV historic data */
 5616|  1.00k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5616:13): [True: 990, False: 11]
  ------------------
 5617|    990|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5617:6): [True: 196, False: 794]
  ------------------
 5618|    196|				size_t datalen;
 5619|    196|				const u8 *data;
 5620|       |
 5621|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5622|    196|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5622:9): [True: 105, False: 91]
  ------------------
 5623|    196|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5624|    105|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5624:10): [True: 29, False: 76]
  |  Branch (5624:26): [True: 20, False: 9]
  ------------------
 5625|     20|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5626|     85|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5626:17): [True: 72, False: 13]
  |  Branch (5626:33): [True: 65, False: 7]
  ------------------
 5627|     65|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5628|     65|					}
 5629|       |					/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
 5630|       |					 * https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
 5631|       |					 * On Windows 10, using Omnikey 5021, the ATR is correct
 5632|       |					 * will look at only 6 bytes that do match
 5633|       |					 */
 5634|     20|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5634:15): [True: 7, False: 13]
  |  Branch (5634:31): [True: 5, False: 2]
  ------------------
 5635|      5|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5636|      5|					}
 5637|    105|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5637:16): [True: 41, False: 50]
  ------------------
 5638|     91|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5639|     41|					int k;
 5640|       |
 5641|    120|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5641:18): [True: 81, False: 39]
  ------------------
 5642|     81|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5642:11): [True: 75, False: 6]
  ------------------
 5643|     75|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5643:9): [True: 2, False: 73]
  ------------------
 5644|      2|							type = SC_CARD_TYPE_PIV_II_HIST;
 5645|      2|							break;
 5646|      2|						}
 5647|     81|					}
 5648|     41|				}
 5649|    196|			}
 5650|  1.15k|		}
 5651|       |
 5652|  5.02k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5653|       |
 5654|  5.02k|		if (type == -1) {
  ------------------
  |  Branch (5654:7): [True: 4.77k, False: 243]
  ------------------
 5655|       |			/* use known ATRs  which changes the type */
 5656|  4.77k|			i = _sc_match_atr(card, piv_atrs, &type);
 5657|  4.77k|			if (i < 0)
  ------------------
  |  Branch (5657:8): [True: 4.77k, False: 6]
  ------------------
 5658|  4.77k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5659|  4.77k|		}
 5660|  5.02k|	}
 5661|       |
 5662|  5.02k|	card->type = type;
 5663|       |
 5664|       |	/* we either found via ATR historic bytes or ATR directly */
 5665|  5.02k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.02k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5666|       |
 5667|       |	/* allocate and init basic fields */
 5668|  5.02k|	priv = calloc(1, sizeof(piv_private_data_t));
 5669|       |
 5670|  5.02k|	if (!priv)
  ------------------
  |  Branch (5670:6): [True: 0, False: 5.02k]
  ------------------
 5671|  5.02k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5672|       |
 5673|  5.02k|	card->drv_data = priv; /* will free if no match, or pass on to piv_init */
 5674|       |	/*
 5675|       |	 * Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
 5676|       |	 * If for some reason future cards have larger objects, this value needs to
 5677|       |	 * be increased here.
 5678|       |	 */
 5679|  5.02k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  220|  5.02k|#define MAX_FILE_SIZE 65535
  ------------------
 5680|  5.02k|	priv->selected_obj = -1;
 5681|  5.02k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5682|  5.02k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|  5.02k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5683|  5.02k|	priv->pstate = PIV_STATE_MATCH;
 5684|       |
 5685|       |#ifdef ENABLE_PIV_SM
 5686|       |	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
 5687|       |	card->sm_ctx.ops.open = piv_sm_open;
 5688|       |	card->sm_ctx.ops.get_sm_apdu = piv_get_sm_apdu;
 5689|       |	card->sm_ctx.ops.free_sm_apdu = piv_free_sm_apdu;
 5690|       |	card->sm_ctx.ops.close = piv_sm_close;
 5691|       |#endif /* ENABLE_PIV_SM */
 5692|       |
 5693|       |	/* See if contactless  or run as virtual card */
 5694|       |	/* PivApplet in .github/test_piv.sh for example */
 5695|  5.02k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5695:6): [True: 1.27k, False: 3.74k]
  ------------------
 5696|  1.27k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5696:4): [True: 1.17k, False: 100]
  ------------------
 5697|  1.17k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5697:4): [True: 71, False: 1.10k]
  ------------------
 5698|     71|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5698:4): [True: 44, False: 27]
  ------------------
 5699|     44|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5699:4): [True: 27, False: 17]
  ------------------
 5700|     27|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  385|     27|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5701|     27|	}
 5702|       |
 5703|   306k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5703:14): [True: 301k, False: 5.02k]
  ------------------
 5704|   301k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  646|   301k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5704:7): [True: 100k, False: 200k]
  ------------------
 5705|   100k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|   105k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5706|       |	/*
 5707|       |	 * Detect if active AID is PIV. NIST 800-73 says only one PIV application per card
 5708|       |	 * and PIV must be the default application.
 5709|       |	 * Try to avoid doing a select_aid and losing the login state on some cards.
 5710|       |	 * We may get interference on some cards by other drivers trying SELECT_AID before
 5711|       |	 * we get to see if PIV application is still active. Putting PIV driver first might help.
 5712|       |	 *
 5713|       |	 * Discovery Object introduced in 800-73-3 so will return OK if found and PIV applet active.
 5714|       |	 * Will fail with SC_ERROR_FILE_NOT_FOUND if 800-73-3 and no Discovery object.
 5715|       |	 * But some other card could also return SC_ERROR_FILE_NOT_FOUND.
 5716|       |	 * Will fail for other reasons if wrong applet is selected or bad PIV implementation.
 5717|       |	 */
 5718|       |
 5719|       |	/*
 5720|       |	 * if ATR matched or user forced card type
 5721|       |	 * test if PIV is active applet without using AID If fails try AID
 5722|       |	 */
 5723|       |
 5724|  5.02k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5724:6): [True: 249, False: 4.77k]
  ------------------
 5725|    249|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  385|    249|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5725:4): [True: 247, False: 2]
  ------------------
 5726|    247|		r = piv_find_discovery(card);
 5727|    247|		if (r < 0) {
  ------------------
  |  Branch (5727:7): [True: 218, False: 29]
  ------------------
 5728|    218|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5729|    218|			r = piv_find_aid(card);
 5730|    218|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|    218|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    218|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    218|	int _ret = (r); \
  |  |  |  |  178|    218|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 76, False: 142]
  |  |  |  |  ------------------
  |  |  |  |  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|    218|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 142]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5731|    218|		}
 5732|  4.77k|	} else {
 5733|       |		/* piv_find_aid saves al_label from response */
 5734|  4.77k|		r = piv_find_aid(card);
 5735|  4.77k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  4.77k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.77k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.77k|	int _ret = (r); \
  |  |  |  |  178|  4.77k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.22k, False: 553]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.22k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.22k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  4.22k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  4.22k|		goto err; \
  |  |  |  |  182|  4.22k|	} \
  |  |  |  |  183|  4.77k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 553]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5736|  4.77k|	}
 5737|       |
 5738|       |	/* Know to be PIV card but not the type */
 5739|       |
 5740|       |	/* If card type still unknown, see if Application Label is known and set card->type */
 5741|    724|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5741:6): [True: 12, False: 712]
  |  Branch (5741:24): [True: 8, False: 4]
  ------------------
 5742|      8|		switch (card->type) {
  ------------------
  |  Branch (5742:11): [True: 7, False: 1]
  ------------------
 5743|      7|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5743:3): [True: 7, False: 1]
  ------------------
 5744|      7|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5744:3): [True: 0, False: 8]
  ------------------
 5745|     13|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5745:16): [True: 7, False: 6]
  ------------------
 5746|      7|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5746:9): [True: 6, False: 1]
  ------------------
 5747|      6|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5747:7): [True: 1, False: 5]
  ------------------
 5748|      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__
  |  |  ------------------
  ------------------
 5749|      1|					card->type = al_map[i].al_type;
 5750|      1|					break;
 5751|      1|				}
 5752|      7|			}
 5753|      7|			break;
 5754|      8|		}
 5755|      8|	}
 5756|       |
 5757|    724|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d  CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    724|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5758|    724|			card->type, priv->card_issues, r, priv->alg_ids);
 5759|       |
 5760|       |	/*
 5761|       |	 * Assumes all Yubikey/Nitrokey/Token2/PivApplet cards are all "Yubico like"
 5762|       |	 * via ATR, ATR Historic bytes or Application Label
 5763|       |	 * Will also check if BASE cards are Yubikey like card and return a version number
 5764|       |	 * SC_CARD_TYPE_PIV_II_GENERIC can be set by user to not test for Yubico version
 5765|       |	 */
 5766|    724|	switch (card->type) {
  ------------------
  |  Branch (5766:10): [True: 716, False: 8]
  ------------------
 5767|     64|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5767:2): [True: 64, False: 660]
  ------------------
 5768|    142|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5768:2): [True: 78, False: 646]
  ------------------
 5769|    161|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5769:2): [True: 19, False: 705]
  ------------------
 5770|    163|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5770:2): [True: 2, False: 722]
  ------------------
 5771|    164|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5771:2): [True: 1, False: 723]
  ------------------
 5772|    164|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5772:2): [True: 0, False: 724]
  ------------------
 5773|    716|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5773:2): [True: 552, False: 172]
  ------------------
 5774|    716|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|    716|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5775|    716|		apdu.lc = 0;
 5776|    716|		apdu.data = NULL;
 5777|    716|		apdu.datalen = 0;
 5778|    716|		apdu.resp = yubico_version_buf;
 5779|    716|		apdu.resplen = sizeof(yubico_version_buf);
 5780|    716|		apdu.le = apdu.resplen;
 5781|    716|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5782|    716|		if (r2 == SC_SUCCESS && apdu.resplen == 3) {
  ------------------
  |  |   28|  1.43k|#define SC_SUCCESS				0
  ------------------
  |  Branch (5782:7): [True: 707, False: 9]
  |  Branch (5782:27): [True: 332, False: 375]
  ------------------
 5783|    332|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5784|    332|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   71|    332|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5785|    332|		}
 5786|    716|		break;
 5787|    724|	}
 5788|       |
 5789|    724|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    724|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5790|    724|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5791|       |
 5792|       |	/* We now know PIV AID is active, test CCC object. 800-73-* say CCC is required */
 5793|       |	/* CCC not readable over contactless, unless using VCI. but dont need CCC for SC_CARD_TYPE_PIV_II_800_73_4 */
 5794|    724|	switch (card->type) {
  ------------------
  |  Branch (5794:10): [True: 556, False: 168]
  ------------------
 5795|       |	/*
 5796|       |	 * For cards that may also be CAC, try and read the CCC
 5797|       |	 * CCC is required and all Dual PIV/CAC will have a CCC
 5798|       |	 * Currently Dual PIV/CAC are based on NIST 800-73-1 which does not have Discovery or History
 5799|       |	 */
 5800|    552|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5800:2): [True: 552, False: 172]
  ------------------
 5801|    552|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5801:2): [True: 0, False: 724]
  ------------------
 5802|    553|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5802:2): [True: 1, False: 723]
  ------------------
 5803|    553|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5803:2): [True: 0, False: 724]
  ------------------
 5804|    554|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5804:2): [True: 1, False: 723]
  ------------------
 5805|    556|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5805:2): [True: 2, False: 722]
  ------------------
 5806|    556|		r2 = piv_process_ccc(card);
 5807|    556|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    556|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5808|    556|				card->type, r2, priv->card_issues, r, priv->alg_ids);
 5809|       |		/* Ignore any error. */
 5810|       |		/* If CCC says it has CAC with PKI on card set to one of the SC_CARD_TYPE_PIV_II_*_DUAL_CAC */
 5811|    556|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  174|    556|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5811:7): [True: 6, False: 550]
  ------------------
 5812|      6|			switch (card->type) {
  ------------------
  |  Branch (5812:12): [True: 6, False: 0]
  ------------------
 5813|      6|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5813:4): [True: 6, False: 0]
  ------------------
 5814|      6|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5814:4): [True: 0, False: 6]
  ------------------
 5815|      6|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5815:4): [True: 0, False: 6]
  ------------------
 5816|      6|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5816:4): [True: 0, False: 6]
  ------------------
 5817|      6|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5818|      6|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      6|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5819|      6|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      6|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5820|      6|				break;
 5821|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5821:4): [True: 0, False: 6]
  ------------------
 5822|      0|				card->type = SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC;
 5823|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5824|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5825|      0|				break;
 5826|      0|			case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5826:4): [True: 0, False: 6]
  ------------------
 5827|      0|				card->type = SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC;
 5828|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5829|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5830|      0|				break;
 5831|      6|			}
 5832|      6|		}
 5833|    556|		break;
 5834|       |
 5835|    556|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5835:2): [True: 0, False: 724]
  ------------------
 5836|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5836:2): [True: 0, False: 724]
  ------------------
 5837|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5837:2): [True: 0, False: 724]
  ------------------
 5838|      0|		priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5839|      0|		priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5840|      0|		break;
 5841|    724|	}
 5842|    724|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    724|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5843|    724|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5844|       |
 5845|       |	/* If contactless or run as virtual card try to get alg refs from AC entries in response to SELECT AID */
 5846|    724|	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  380|    724|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
              	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  385|     29|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5846:6): [True: 29, False: 695]
  |  Branch (5846:51): [True: 0, False: 29]
  ------------------
 5847|      0|		r2 = piv_find_aid(card);
 5848|      0|	}
 5849|       |
 5850|       |	/* Read AID if needed for these cards types */
 5851|    724|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  380|    724|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5851:6): [True: 29, False: 695]
  ------------------
 5852|     29|		switch (card->type) {
  ------------------
  |  Branch (5852:11): [True: 1, False: 28]
  ------------------
 5853|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5853:3): [True: 0, False: 29]
  ------------------
 5854|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5854:3): [True: 0, False: 29]
  ------------------
 5855|      0|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5855:3): [True: 0, False: 29]
  ------------------
 5856|      0|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5856:3): [True: 0, False: 29]
  ------------------
 5857|      1|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5857:3): [True: 1, False: 28]
  ------------------
 5858|      1|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5858:3): [True: 0, False: 29]
  ------------------
 5859|      1|			r2 = piv_find_aid(card);
 5860|     29|		}
 5861|     29|	}
 5862|       |
 5863|    724|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    724|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5864|    724|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5865|       |
 5866|       |	/* if card did not specify any of the NIST basic alg_ids add them */
 5867|    724|	if ((priv->alg_ids & AI_NIST) == 0) {
  ------------------
  |  |  609|    724|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  600|    724|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  601|    724|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  602|    724|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  604|    724|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  605|    724|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
  |  Branch (5867:6): [True: 722, False: 2]
  ------------------
 5868|    722|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  609|    722|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  600|    722|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  601|    722|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  602|    722|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  604|    722|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  605|    722|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 5869|    722|	}
 5870|       |
 5871|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 5872|    724|	switch (card->type) {
  ------------------
  |  Branch (5872:10): [True: 546, False: 178]
  ------------------
 5873|    546|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5873:2): [True: 546, False: 178]
  ------------------
 5874|    546|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5874:2): [True: 0, False: 724]
  ------------------
 5875|    546|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  381|    546|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (5875:7): [True: 0, False: 546]
  ------------------
 5876|      0|			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5877|      0|		}
 5878|       |
 5879|       |#ifdef ENABLE_PIV_SM
 5880|       |		/* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
 5881|       |		if ((priv->pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC)) != 0) {
 5882|       |			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5883|       |		}
 5884|       |#endif
 5885|    546|		break;
 5886|    724|	}
 5887|       |
 5888|    724|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    724|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5889|    724|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5890|       |
 5891|       |	/*
 5892|       |	 * Set card_issues flags based card->type and version numbers if available.
 5893|       |	 *
 5894|       |	 * YubiKey NEO, Yubikey 4 and other devices with PIV applets, have compliance
 5895|       |	 * issues with the NIST 800-73-3 specs. The OpenSC developers do not have
 5896|       |	 * access to all the different devices or versions of the devices.
 5897|       |	 * Vendor and user input is welcome on any compliance issues.
 5898|       |	 *
 5899|       |	 * For the Yubico devices The assumption is also made that if a bug is
 5900|       |	 * fixed in a Yubico version that means it is fixed on both NEO and Yubikey 4.
 5901|       |	 *
 5902|       |	 * The flags CI_CANT_USE_GETDATA_FOR_STATE and CI_DISCOVERY_USELESS
 5903|       |	 * may be set earlier or later then in the following code.
 5904|       |	 */
 5905|       |
 5906|    724|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    724|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5907|    724|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5908|    724|	switch (card->type) {
 5909|     64|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5909:2): [True: 64, False: 660]
  ------------------
 5910|     64|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  596|     64|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 5911|     64|				     CI_VERIFY_630X |
  ------------------
  |  |  584|     64|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 5912|     64|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  593|     64|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5913|     64|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  589|     64|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5914|     64|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  594|     64|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 5915|     64|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5915:7): [True: 50, False: 14]
  ------------------
 5916|     50|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  585|     50|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5917|     64|		break;
 5918|       |
 5919|     78|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5919:2): [True: 78, False: 646]
  ------------------
 5920|     79|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5920:2): [True: 1, False: 723]
  ------------------
 5921|     81|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5921:2): [True: 2, False: 722]
  ------------------
 5922|     81|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  593|     81|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5923|     81|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  589|     81|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5924|     81|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5924:7): [True: 55, False: 26]
  ------------------
 5925|     55|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  585|     55|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5926|     81|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (5926:7): [True: 23, False: 58]
  ------------------
 5927|     23|			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  603|     23|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  606|     23|#define AI_25519			    0x00100000U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  607|     23|#define AI_X25519			    0x00200000U
  ------------------
 5928|     81|		break;
 5929|       |
 5930|     19|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5930:2): [True: 19, False: 705]
  ------------------
 5931|     19|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|     19|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5932|     19|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (5932:7): [True: 9, False: 10]
  ------------------
 5933|      9|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  603|      9|#define AI_RSA_4096			    0x00000008U
  ------------------
 5934|     19|		break;
 5935|       |
 5936|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5936:2): [True: 0, False: 724]
  ------------------
 5937|      2|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5937:2): [True: 2, False: 722]
  ------------------
 5938|      3|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5938:2): [True: 1, False: 723]
  ------------------
 5939|      3|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5939:2): [True: 0, False: 724]
  ------------------
 5940|      3|		priv->card_issues |= 0; /* could add others here */
 5941|      3|		break;
 5942|       |
 5943|    546|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5943:2): [True: 546, False: 178]
  ------------------
 5944|    547|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5944:2): [True: 1, False: 723]
  ------------------
 5945|    548|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5945:2): [True: 1, False: 723]
  ------------------
 5946|    548|		priv->card_issues |= 0; /* could add others here */
 5947|    548|		break;
 5948|       |
 5949|      6|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5949:2): [True: 6, False: 718]
  ------------------
 5950|      6|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5950:2): [True: 0, False: 724]
  ------------------
 5951|      6|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5951:2): [True: 0, False: 724]
  ------------------
 5952|      6|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      6|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5953|      6|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  591|      6|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5954|      6|				     CI_NO_RANDOM |
  ------------------
  |  |  587|      6|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5955|      6|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|      6|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5956|      6|		break;
 5957|       |
 5958|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5958:2): [True: 0, False: 724]
  ------------------
 5959|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5960|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5961|      0|		break;
 5962|       |
 5963|      3|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5963:2): [True: 3, False: 721]
  ------------------
 5964|      3|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      3|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5965|      3|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  591|      3|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5966|      3|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  587|      3|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5967|       |							     /* Discovery object returns 6A 82 so is not on card by default */
 5968|      3|		break;
 5969|       |
 5970|      0|	default:
  ------------------
  |  Branch (5970:2): [True: 0, False: 724]
  ------------------
 5971|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  585|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5972|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  593|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5973|       |		/* opensc.conf may have it wrong, continue anyway */
 5974|      0|		sc_log(card->ctx, "Unknown PIV card->type %d", card->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5975|      0|		card->type = SC_CARD_TYPE_PIV_II_GENERIC;
 5976|    724|	}
 5977|    724|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5978|    724|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5979|       |
 5980|    724|	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  590|    724|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
              	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  382|    718|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (5980:6): [True: 718, False: 6]
  |  Branch (5980:53): [True: 689, False: 29]
  ------------------
 5981|       |		/*
 5982|       |		 * We now know PIV AID is active, test DISCOVERY object again
 5983|       |		 * Some PIV don't support DISCOVERY and return
 5984|       |		 * SC_ERROR_INCORRECT_PARAMETERS. Any error
 5985|       |		 * including SC_ERROR_FILE_NOT_FOUND means we cannot use discovery
 5986|       |		 * to test for active AID.
 5987|       |		 */
 5988|    689|		r2 = piv_find_discovery(card);
 5989|       |
 5990|    689|		if (r2 < 0) {
  ------------------
  |  Branch (5990:7): [True: 675, False: 14]
  ------------------
 5991|    675|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  590|    675|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5992|    675|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  153|    675|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5993|    675|		}
 5994|    689|	}
 5995|       |
 5996|    724|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5997|    724|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5998|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 5999|    724|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    724|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    724|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    724|	int _ret = r; \
  |  |  |  |  155|    724|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 724, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    724|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 724]
  |  |  |  |  ------------------
  |  |  |  |  157|    724|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    724|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    724|	return _ret; \
  |  |  |  |  163|    724|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6000|       |
 6001|  4.29k|err:
 6002|  4.29k|	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.29k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6003|  4.29k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6004|       |	/* don't match. Does not have a PIV applet. */
 6005|  4.29k|	piv_finish(card);
 6006|  4.29k|	card->type = saved_type;
 6007|  4.29k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.29k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.29k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.29k|	int _ret = r; \
  |  |  |  |  155|  4.29k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.29k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.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|  4.29k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.29k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.29k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.29k|	return _ret; \
  |  |  |  |  163|  4.29k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6008|  4.29k|}
card-piv.c:piv_find_discovery:
 5158|    986|{
 5159|    986|	int r = 0;
 5160|    986|	size_t rbuflen;
 5161|    986|	u8 *rbuf = NULL;
 5162|    986|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    986|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5163|       |
 5164|    986|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    986|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    986|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    986|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 986]
  |  |  ------------------
  ------------------
 5165|       |
 5166|       |	/*
 5167|       |	 * During piv_card_reader_lock_obtained,
 5168|       |	 * we use the discovery object to test if card present, and
 5169|       |	 * if PIV AID is active.
 5170|       |	 */
 5171|    986|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|    986|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5171:6): [True: 0, False: 986]
  ------------------
 5172|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 5173|      0|		goto end;
 5174|      0|	}
 5175|       |
 5176|       |	/* If not valid: read, test,  cache */
 5177|    986|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  151|    986|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5177:6): [True: 936, False: 50]
  ------------------
 5178|    936|		r = piv_process_discovery(card);
 5179|    936|	} else {
 5180|       |		/* if already in cache,force read */
 5181|     50|		rbuflen = 1;
 5182|     50|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5183|       |		/* if same response as last, no need to parse */
 5184|     50|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5184:7): [True: 0, False: 50]
  |  Branch (5184:17): [True: 0, False: 0]
  ------------------
 5185|      0|			goto end;
 5186|       |
 5187|     50|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5187:7): [True: 16, False: 34]
  |  Branch (5187:17): [True: 13, False: 3]
  ------------------
 5188|     13|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5188:5): [True: 13, False: 0]
  ------------------
 5189|     13|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5189:5): [True: 9, False: 4]
  ------------------
 5190|      9|			goto end;
 5191|      9|		}
 5192|       |		/* This should not happen  bad card */
 5193|     41|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5194|     41|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     41|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5195|     41|		goto end;
 5196|     50|	}
 5197|       |
 5198|    986|end:
 5199|    986|	free(rbuf);
 5200|    986|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    986|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    986|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    986|	int _ret = r; \
  |  |  |  |  155|    986|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 977, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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|    934|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 934, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|    977|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    977|	} 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|    986|	return _ret; \
  |  |  |  |  163|    986|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5201|    986|}
card-piv.c:piv_process_discovery:
 5051|    936|{
 5052|    936|	int r;
 5053|    936|	u8 *rbuf = NULL;
 5054|    936|	size_t rbuflen = 0;
 5055|       |
 5056|    936|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5057|       |	/* Note rbuf and rbuflen are now pointers into cache */
 5058|    936|	if (r < 0)
  ------------------
  |  Branch (5058:6): [True: 863, False: 73]
  ------------------
 5059|    863|		goto err;
 5060|       |
 5061|       |	/* the object is now cached, see what we have */
 5062|     73|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 5063|       |
 5064|    936|err:
 5065|    936|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    936|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    936|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    936|	int _ret = r; \
  |  |  |  |  155|    936|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 936, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    936|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    893|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 893, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|    936|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    936|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    936|	return _ret; \
  |  |  |  |  163|    936|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5066|    936|}
card-piv.c:piv_get_cached_data:
 3201|  7.74k|{
 3202|       |
 3203|  7.74k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  7.74k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3204|  7.74k|	int r;
 3205|  7.74k|	u8 *rbuf = NULL;
 3206|  7.74k|	size_t rbuflen;
 3207|       |
 3208|  7.74k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.74k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.74k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.74k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.74k]
  |  |  ------------------
  ------------------
 3209|       |
 3210|  7.74k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3210:6): [True: 0, False: 7.74k]
  |  Branch (3210:21): [True: 0, False: 7.74k]
  ------------------
 3211|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3212|       |
 3213|  7.74k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  7.74k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3214|       |
 3215|       |	/* see if we have it cached */
 3216|  7.74k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  151|  7.74k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3216:6): [True: 502, False: 7.23k]
  ------------------
 3217|       |
 3218|    502|		sc_log(card->ctx, "found #%d %p:%zu %p:%zu",
  ------------------
  |  |   71|    502|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3219|    502|				enumtag,
 3220|    502|				priv->obj_cache[enumtag].obj_data,
 3221|    502|				priv->obj_cache[enumtag].obj_len,
 3222|    502|				priv->obj_cache[enumtag].internal_obj_data,
 3223|    502|				priv->obj_cache[enumtag].internal_obj_len);
 3224|       |
 3225|    502|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3225:7): [True: 0, False: 502]
  ------------------
 3226|      0|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3227|      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__
  |  |  ------------------
  ------------------
 3228|      0|			goto err;
 3229|      0|		}
 3230|    502|		*buf = priv->obj_cache[enumtag].obj_data;
 3231|    502|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3232|    502|		r = (int)*buf_len;
 3233|    502|		goto ok;
 3234|    502|	}
 3235|       |
 3236|       |	/*
 3237|       |	 * If we know it can not be on the card  i.e. History object
 3238|       |	 * has been read, and we know what other certs may or
 3239|       |	 * may not be on the card. We can avoid extra overhead
 3240|       |	 * Also used if object on card was not parsable
 3241|       |	 */
 3242|       |
 3243|  7.23k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  7.23k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3243:6): [True: 0, False: 7.23k]
  ------------------
 3244|      0|		sc_log(card->ctx, "no_obj #%d", enumtag);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3245|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3246|      0|		goto err;
 3247|      0|	}
 3248|       |
 3249|       |	/* Not cached, try to get it, piv_get_data will allocate a buf */
 3250|  7.23k|	sc_log(card->ctx, "get #%d", enumtag);
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
 3251|  7.23k|	rbuflen = 1;
 3252|  7.23k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3253|  7.23k|	if (r > 0) {
  ------------------
  |  Branch (3253:6): [True: 971, False: 6.26k]
  ------------------
 3254|    971|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|    971|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3255|    971|		priv->obj_cache[enumtag].obj_len = r;
 3256|    971|		priv->obj_cache[enumtag].obj_data = rbuf;
 3257|    971|		*buf = rbuf;
 3258|    971|		*buf_len = r;
 3259|       |
 3260|    971|		sc_log(card->ctx, "added #%d  %p:%zu %p:%zu",
  ------------------
  |  |   71|    971|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3261|    971|				enumtag,
 3262|    971|				priv->obj_cache[enumtag].obj_data,
 3263|    971|				priv->obj_cache[enumtag].obj_len,
 3264|    971|				priv->obj_cache[enumtag].internal_obj_data,
 3265|    971|				priv->obj_cache[enumtag].internal_obj_len);
 3266|       |
 3267|  6.26k|	} else {
 3268|  6.26k|		free(rbuf);
 3269|  6.26k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  6.26k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3269:7): [True: 0, False: 6.26k]
  |  Branch (3269:17): [True: 494, False: 5.77k]
  ------------------
 3270|    494|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    494|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3271|    494|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|    494|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3272|    494|			priv->obj_cache[enumtag].obj_len = 0;
 3273|  5.77k|		} else {
 3274|  5.77k|			goto err;
 3275|  5.77k|		}
 3276|  6.26k|	}
 3277|  1.96k|ok:
 3278|       |
 3279|  7.74k|err:
 3280|  7.74k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.74k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.74k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.74k|	int _ret = r; \
  |  |  |  |  155|  7.74k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.26k, False: 1.47k]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.26k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.26k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.26k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.26k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.26k|	} else { \
  |  |  |  |  159|  1.47k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.47k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.47k|	} \
  |  |  |  |  162|  7.74k|	return _ret; \
  |  |  |  |  163|  7.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3281|  7.74k|}
card-piv.c:piv_parse_discovery:
 4995|     73|{
 4996|     73|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     73|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4997|     73|	int r = 0;
 4998|     73|	const u8 *body;
 4999|     73|	size_t bodylen;
 5000|     73|	const u8 *aid;
 5001|     73|	size_t aidlen;
 5002|     73|	const u8 *pinp;
 5003|     73|	size_t pinplen;
 5004|     73|	unsigned int cla_out, tag_out;
 5005|       |
 5006|     73|	if (rbuflen != 0) {
  ------------------
  |  Branch (5006:6): [True: 73, False: 0]
  ------------------
 5007|     73|		body = rbuf;
 5008|     73|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    146|#define SC_SUCCESS				0
  ------------------
  |  Branch (5008:7): [True: 0, False: 73]
  ------------------
 5009|     73|				body == NULL ||
  ------------------
  |  Branch (5009:5): [True: 0, False: 73]
  ------------------
 5010|     73|				bodylen == 0 ||
  ------------------
  |  Branch (5010:5): [True: 2, False: 71]
  ------------------
 5011|     71|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (5011:5): [True: 0, False: 71]
  ------------------
 5012|      2|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5013|      2|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5014|      2|			goto err;
 5015|      2|		}
 5016|       |
 5017|     71|		sc_log(card->ctx, "Discovery 0x%2.2x 0x%2.2x %p:%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5018|     71|				cla_out, tag_out, body, bodylen);
 5019|     71|		aidlen = 0;
 5020|     71|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 5021|     71|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (5021:7): [True: 5, False: 66]
  |  Branch (5021:22): [True: 1, False: 65]
  ------------------
 5022|     65|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (5022:5): [True: 22, False: 43]
  ------------------
 5023|     28|			sc_log(card->ctx, "Discovery object not PIV");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5024|     28|			r = SC_ERROR_INVALID_CARD; /* This is an error */
  ------------------
  |  |   60|     28|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 5025|     28|			goto err;
 5026|     28|		}
 5027|     43|		if (aid_only == 0) {
  ------------------
  |  Branch (5027:7): [True: 43, False: 0]
  ------------------
 5028|     43|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 5029|     43|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (5029:8): [True: 21, False: 22]
  |  Branch (5029:16): [True: 19, False: 2]
  ------------------
 5030|     19|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  383|     19|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 5031|     19|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 5032|     19|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5033|     19|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|     19|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|     19|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|     19|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|     19|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (5033:9): [True: 3, False: 16]
  ------------------
 5034|      3|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  377|      3|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (5034:7): [True: 1, False: 2]
  ------------------
 5035|      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__
  |  |  ------------------
  ------------------
 5036|      1|					priv->pin_preference = 0x00;
 5037|      1|				}
 5038|     19|			}
 5039|     43|		}
 5040|     43|		r = SC_SUCCESS;
  ------------------
  |  |   28|     43|#define SC_SUCCESS				0
  ------------------
 5041|     43|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  382|     43|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 5042|     43|	}
 5043|       |
 5044|     73|err:
 5045|     73|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 30, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5046|     73|}
card-piv.c:piv_get_data:
 3091|  7.28k|{
 3092|  7.28k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  7.28k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3093|  7.28k|	u8 *p;
 3094|  7.28k|	u8 *tbuf;
 3095|  7.28k|	int r = 0;
 3096|  7.28k|	u8 tagbuf[8];
 3097|  7.28k|	size_t tag_len;
 3098|  7.28k|	int alloc_buf = 0;
 3099|       |
 3100|  7.28k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.28k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.28k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.28k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.28k]
  |  |  ------------------
  ------------------
 3101|       |
 3102|  7.28k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
 3103|       |
 3104|  7.28k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3105|  7.28k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  7.28k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3105:6): [True: 0, False: 7.28k]
  ------------------
 3106|      0|		sc_log(card->ctx, "sc_lock failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3107|      0|		return r;
 3108|      0|	}
 3109|       |
 3110|  7.28k|	tag_len = piv_objects[enumtag].tag_len;
 3111|       |
 3112|  7.28k|	p = tagbuf;
 3113|  7.28k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3114|  7.28k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  7.28k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3114:6): [True: 0, False: 7.28k]
  ------------------
 3115|      0|		sc_log(card->ctx, "Failed to encode ASN1 tag");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3116|      0|		goto err;
 3117|      0|	}
 3118|       |
 3119|  7.28k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3119:6): [True: 7.28k, False: 0]
  |  Branch (3119:23): [True: 7.28k, False: 0]
  ------------------
 3120|  7.28k|		*buf_len = priv->max_object_size; /* will allocate below */
 3121|  7.28k|		alloc_buf = 1;
 3122|  7.28k|	}
 3123|       |
 3124|  7.28k|	sc_log(card->ctx, "buffer for #%d *buf=0x%p len=%zu", enumtag, *buf, *buf_len);
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
 3125|  7.28k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3125:6): [True: 7.28k, False: 0]
  |  Branch (3125:22): [True: 7.28k, False: 0]
  ------------------
 3126|  7.28k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  7.28k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3126:7): [True: 0, False: 7.28k]
  ------------------
 3127|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3128|      0|			goto err;
 3129|      0|		}
 3130|  7.28k|		*buf = malloc(*buf_len);
 3131|  7.28k|		if (*buf == NULL) {
  ------------------
  |  Branch (3131:7): [True: 0, False: 7.28k]
  ------------------
 3132|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3133|      0|			goto err;
 3134|      0|		}
 3135|  7.28k|	}
 3136|       |
 3137|       |#ifdef ENABLE_PIV_SM
 3138|       |	/*
 3139|       |	 * Over contact reader, OK to read non sensitive object in clear even when SM is active
 3140|       |	 * but only if using default policy and we are not in reader_lock_obtained
 3141|       |	 * Discovery object will use SM from reader_lock_obtained to catch if SM is still valid
 3142|       |	 * i.e. no interference from other applications
 3143|       |	 */
 3144|       |	sc_log(card->ctx, "enumtag:%d sm_ctx.sm_mode:%d piv_objects[enumtag].flags:0x%8.8x sm_flags:0x%8.8lx it_flags:0x%8.8x",
 3145|       |			enumtag, card->sm_ctx.sm_mode, piv_objects[enumtag].flags, priv->sm_flags, priv->init_flags);
 3146|       |	if (priv->sm_flags & PIV_SM_FLAGS_SM_IS_ACTIVE &&
 3147|       |			enumtag != PIV_OBJ_DISCOVERY &&
 3148|       |			card->sm_ctx.sm_mode == SM_MODE_TRANSMIT &&
 3149|       |			!(piv_objects[enumtag].flags & PIV_OBJECT_NEEDS_PIN) &&
 3150|       |			!(priv->sm_flags & (PIV_SM_FLAGS_NEVER | PIV_SM_FLAGS_ALWAYS)) &&
 3151|       |			!(priv->init_flags & (PIV_INIT_CONTACTLESS | PIV_INIT_IN_READER_LOCK_OBTAINED))) {
 3152|       |		sc_log(card->ctx, "Set PIV_SM_GET_DATA_IN_CLEAR");
 3153|       |		priv->sm_flags |= PIV_SM_GET_DATA_IN_CLEAR;
 3154|       |	}
 3155|       |
 3156|       |#endif /* ENABLE_PIV_SM */
 3157|  7.28k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3158|  7.28k|	if (r > 0) {
  ------------------
  |  Branch (3158:6): [True: 1.29k, False: 5.99k]
  ------------------
 3159|  1.29k|		int r_tag;
 3160|  1.29k|		unsigned int cla_out, tag_out;
 3161|  1.29k|		size_t bodylen = 0;
 3162|  1.29k|		const u8 *body = *buf;
 3163|  1.29k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3164|  1.29k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  2.58k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3164:7): [True: 156, False: 1.13k]
  |  Branch (3164:30): [True: 35, False: 1.10k]
  ------------------
 3165|  1.10k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3165:5): [True: 113, False: 987]
  ------------------
 3166|    304|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   71|    304|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3167|    304|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    304|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3168|    304|			goto err;
 3169|    304|		}
 3170|    987|		*buf_len = (body - *buf) + bodylen;
 3171|  5.99k|	} else if (r == 0) {
  ------------------
  |  Branch (3171:13): [True: 141, False: 5.85k]
  ------------------
 3172|    141|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    141|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3173|    141|		goto err;
 3174|  5.85k|	} else {
 3175|  5.85k|		goto err;
 3176|  5.85k|	}
 3177|       |
 3178|    987|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3178:6): [True: 987, False: 0]
  |  Branch (3178:19): [True: 987, False: 0]
  ------------------
 3179|    987|		tbuf = malloc(r);
 3180|    987|		if (tbuf == NULL) {
  ------------------
  |  Branch (3180:7): [True: 0, False: 987]
  ------------------
 3181|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3182|      0|			goto err;
 3183|      0|		}
 3184|    987|		memcpy(tbuf, *buf, r);
 3185|    987|		free(*buf);
 3186|    987|		alloc_buf = 0;
 3187|    987|		*buf = tbuf;
 3188|    987|	}
 3189|       |
 3190|  7.28k|err:
 3191|  7.28k|	if (alloc_buf) {
  ------------------
  |  Branch (3191:6): [True: 6.30k, False: 987]
  ------------------
 3192|  6.30k|		free(*buf);
 3193|  6.30k|		*buf = NULL;
 3194|  6.30k|	}
 3195|  7.28k|	sc_unlock(card);
 3196|  7.28k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.28k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.28k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.28k|	int _ret = r; \
  |  |  |  |  155|  7.28k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.30k, False: 987]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.30k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.30k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.30k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.30k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.30k|	} else { \
  |  |  |  |  159|    987|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    987|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    987|	} \
  |  |  |  |  162|  7.28k|	return _ret; \
  |  |  |  |  163|  7.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3197|  7.28k|}
card-piv.c:piv_general_io:
 1794|  7.32k|{
 1795|  7.32k|	int r;
 1796|  7.32k|	sc_apdu_t apdu;
 1797|       |
 1798|  7.32k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1799|       |
 1800|  7.32k|	r = sc_lock(card);
 1801|  7.32k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  7.32k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1801:6): [True: 0, False: 7.32k]
  ------------------
 1802|  7.32k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1803|       |
 1804|  7.32k|	sc_format_apdu(card, &apdu,
 1805|  7.32k|			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  294|  7.32k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1805:4): [True: 7.32k, False: 0]
  ------------------
 1806|  7.32k|			ins, p1, p2);
 1807|  7.32k|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  7.32k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1808|       |#ifdef ENABLE_PIV_SM
 1809|       |	if (card->sm_ctx.sm_mode != SM_MODE_NONE && sendbuflen > 255) {
 1810|       |		/* tell apdu.c to not do the chaining, let the SM get_apdu do it */
 1811|       |		apdu.flags |= SC_APDU_FLAGS_SM_CHAINING;
 1812|       |	}
 1813|       |#endif
 1814|  7.32k|	apdu.lc = sendbuflen;
 1815|  7.32k|	apdu.datalen = sendbuflen;
 1816|  7.32k|	apdu.data = sendbuf;
 1817|       |
 1818|  7.32k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1818:6): [True: 7.32k, False: 0]
  |  Branch (1818:17): [True: 7.32k, False: 0]
  ------------------
 1819|  7.32k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1819:13): [True: 7.32k, False: 0]
  ------------------
 1820|  7.32k|		apdu.resplen = recvbuflen;
 1821|  7.32k|	} else {
 1822|      0|		apdu.le = 0;
 1823|      0|		apdu.resplen = 0;
 1824|      0|	}
 1825|  7.32k|	apdu.resp = recvbuf;
 1826|       |
 1827|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1828|  7.32k|	r = sc_transmit_apdu(card, &apdu);
 1829|       |
 1830|       |	/* adpu will not have sw1,sw2 set because sc_sm_single_transmit called sc_sm_stop, */
 1831|  7.32k|	if (r < 0) {
  ------------------
  |  Branch (1831:6): [True: 59, False: 7.26k]
  ------------------
 1832|     59|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|     59|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1833|     59|		goto err;
 1834|     59|	}
 1835|       |
 1836|  7.26k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1836:6): [True: 53, False: 7.21k]
  |  Branch (1836:26): [True: 20, False: 33]
  ------------------
 1837|     20|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|     20|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1838|  7.24k|	else
 1839|  7.24k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1840|       |
 1841|  7.26k|	if (r < 0) {
  ------------------
  |  Branch (1841:6): [True: 5.82k, False: 1.44k]
  ------------------
 1842|  5.82k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  5.82k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1843|  5.82k|		goto err;
 1844|  5.82k|	}
 1845|       |
 1846|  1.44k|	r = (int)apdu.resplen;
 1847|       |
 1848|  7.32k|err:
 1849|  7.32k|	sc_unlock(card);
 1850|  7.32k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.32k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.32k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.32k|	int _ret = r; \
  |  |  |  |  155|  7.32k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.02k, False: 1.30k]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.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|  5.88k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.88k, False: 141]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.02k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.02k|	} else { \
  |  |  |  |  159|  1.30k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.30k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.30k|	} \
  |  |  |  |  162|  7.32k|	return _ret; \
  |  |  |  |  163|  7.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1851|  7.32k|}
card-piv.c:piv_obj_cache_free_entry:
 5455|   302k|{
 5456|   302k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|   302k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5457|       |
 5458|   302k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5458:6): [True: 971, False: 301k]
  ------------------
 5459|    971|		free(priv->obj_cache[enumtag].obj_data);
 5460|   302k|	priv->obj_cache[enumtag].obj_data = NULL;
 5461|   302k|	priv->obj_cache[enumtag].obj_len = 0;
 5462|       |
 5463|   302k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5463:6): [True: 502, False: 301k]
  ------------------
 5464|    502|		free(priv->obj_cache[enumtag].internal_obj_data);
 5465|   302k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5466|   302k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5467|   302k|	priv->obj_cache[enumtag].flags = flags;
 5468|       |
 5469|   302k|	return SC_SUCCESS;
  ------------------
  |  |   28|   302k|#define SC_SUCCESS				0
  ------------------
 5470|   302k|}
card-piv.c:piv_find_aid:
 2903|  5.00k|{
 2904|  5.00k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  5.00k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2905|  5.00k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2906|  5.00k|	int r, i, j;
 2907|  5.00k|	const u8 *tag;
 2908|  5.00k|	size_t taglen;
 2909|  5.00k|	const u8 *nextac;
 2910|  5.00k|	const u8 *next80;
 2911|  5.00k|	const u8 *pix;
 2912|  5.00k|	size_t pixlen;
 2913|  5.00k|	const u8 *al_label;
 2914|  5.00k|	size_t al_labellen;
 2915|  5.00k|	const u8 *actag; /* Cipher Suite */
 2916|  5.00k|	size_t actaglen;
 2917|  5.00k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2918|  5.00k|	size_t csailen;
 2919|  5.00k|	size_t resplen = sizeof(rbuf);
 2920|       |#ifdef ENABLE_PIV_SM
 2921|       |	int found_csai = 0;
 2922|       |#endif
 2923|       |
 2924|  5.00k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.00k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.00k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.00k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.00k]
  |  |  ------------------
  ------------------
 2925|       |
 2926|       |	/* first  see if the default application will return a template
 2927|       |	 * that we know about.
 2928|       |	 */
 2929|       |
 2930|  5.00k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2931|  5.00k|	if (r > 0 && priv->aid_der.value && resplen == priv->aid_der.len && !memcmp(priv->aid_der.value, rbuf, resplen)) {
  ------------------
  |  Branch (2931:6): [True: 0, False: 5.00k]
  |  Branch (2931:15): [True: 0, False: 0]
  |  Branch (2931:38): [True: 0, False: 0]
  |  Branch (2931:70): [True: 0, False: 0]
  ------------------
 2932|      0|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2933|       |		/* no need to parse again, same as last time */
 2934|      0|	}
 2935|  5.00k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2935:6): [True: 851, False: 4.15k]
  |  Branch (2935:16): [True: 795, False: 56]
  ------------------
 2936|    795|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2937|    795|		if (tag != NULL) {
  ------------------
  |  Branch (2937:7): [True: 757, False: 38]
  ------------------
 2938|    757|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  380|    757|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
 2939|       |			/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
 2940|       |			/* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
 2941|       |			 * where xx is the SM csID either 27 or 2E.
 2942|       |			 * Some vendors may include entries for supported Algorithms even when
 2943|       |			 * not required. We will use these if possible
 2944|       |			 * Will look for multiple 0x80 with in 0xAC value too.
 2945|       |			 */
 2946|    757|			nextac = tag;
 2947|    836|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2947:11): [True: 79, False: 757]
  ------------------
 2948|    836|						0xAC, &actaglen)) != NULL) {
 2949|     79|				nextac = actag + actaglen;
 2950|       |
 2951|     79|				next80 = actag;
 2952|    198|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2952:12): [True: 119, False: 79]
  ------------------
 2953|    198|							0x80, &csailen)) != NULL) {
 2954|    119|					next80 = csai + csailen;
 2955|    119|					if (csailen == 1) {
  ------------------
  |  Branch (2955:10): [True: 31, False: 88]
  ------------------
 2956|     31|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   71|     31|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2957|     31|						j = piv_ai_map_find_by_id(card, *csai);
 2958|     31|						if (j >= 0) {
  ------------------
  |  Branch (2958:11): [True: 16, False: 15]
  ------------------
 2959|     16|							priv->alg_ids |= ai_map[j].ai_flag;
 2960|     16|							continue;
 2961|     16|						}
 2962|       |#ifdef ENABLE_PIV_SM
 2963|       |						/* check if id is NIST SM */
 2964|       |						for (i = 0; i < PIV_CSS_SIZE; i++) {
 2965|       |							if (*csai != css[i].id)
 2966|       |								continue;
 2967|       |							if (found_csai) {
 2968|       |								sc_log(card->ctx, "found multiple csIDs, using first");
 2969|       |							} else {
 2970|       |								priv->cs = &css[i];
 2971|       |								priv->csID = *csai;
 2972|       |								found_csai++;
 2973|       |								priv->init_flags |= PIV_INIT_AID_AC_SM;
 2974|       |							}
 2975|       |						}
 2976|       |#endif /* ENABLE_PIV_SM */
 2977|     31|					}
 2978|    119|				}
 2979|     79|			}
 2980|       |
 2981|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2982|    757|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2983|    757|			if (al_label != NULL) {
  ------------------
  |  Branch (2983:8): [True: 12, False: 745]
  ------------------
 2984|     12|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  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__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2985|     12|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2985:9): [True: 0, False: 12]
  ------------------
 2986|      0|					LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2987|      0|				}
 2988|     12|				memcpy(priv->al_label, al_label, al_labellen);
 2989|     12|				priv->al_labellen = (int)al_labellen;
 2990|     12|			}
 2991|       |
 2992|    757|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 2993|    757|			if (pix != NULL) {
  ------------------
  |  Branch (2993:8): [True: 726, False: 31]
  ------------------
 2994|    726|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   71|    726|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2995|       |
 2996|       |				/* early cards returned full AID, rather then just the pix */
 2997|    788|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (2997:17): [True: 758, False: 30]
  ------------------
 2998|    758|					if ((pixlen >= piv_aids[i].len_long - 5 &&
  ------------------
  |  Branch (2998:11): [True: 746, False: 12]
  ------------------
 2999|    746|							    memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (2999:12): [True: 601, False: 145]
  ------------------
 3000|    157|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (3000:10): [True: 142, False: 15]
  |  Branch (3000:45): [True: 95, False: 47]
  ------------------
 3001|    696|													     piv_aids[i].len_short) == 0))) {
 3002|    696|						free(priv->aid_der.value); /* free previous value if any */
 3003|    696|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (3003:11): [True: 0, False: 696]
  ------------------
 3004|      0|							LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3005|      0|						}
 3006|    696|						memcpy(priv->aid_der.value, rbuf, resplen);
 3007|    696|						priv->aid_der.len = resplen;
 3008|    696|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|    696|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    696|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    696|	int _ret = r; \
  |  |  |  |  155|    696|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 694, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  156|    694|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 694]
  |  |  |  |  ------------------
  |  |  |  |  157|    694|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    694|	} 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|    696|	return _ret; \
  |  |  |  |  163|    696|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3009|    696|					}
 3010|    758|				}
 3011|    726|			}
 3012|    757|		}
 3013|    795|	}
 3014|       |
 3015|  4.31k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|  4.31k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.31k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.31k|	int _ret = r; \
  |  |  |  |  155|  4.31k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.31k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.31k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.31k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.31k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.31k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.31k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.31k|	return _ret; \
  |  |  |  |  163|  4.31k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3016|  4.31k|}
card-piv.c:piv_ai_map_find_by_id:
 2886|     31|{
 2887|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2888|     31|	int i;
 2889|       |
 2890|    191|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2890:14): [True: 176, False: 15]
  ------------------
 2891|    176|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2891:7): [True: 16, False: 160]
  ------------------
 2892|     16|			return i;
 2893|    176|	}
 2894|     15|	return -1;
 2895|     31|}
card-piv.c:piv_process_ccc:
 5139|    556|{
 5140|    556|	int r = 0;
 5141|    556|	u8 *rbuf = NULL;
 5142|    556|	size_t rbuflen = 0;
 5143|       |
 5144|    556|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    556|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    556|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    556|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 556]
  |  |  ------------------
  ------------------
 5145|    556|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5146|       |
 5147|    556|	if (r < 0)
  ------------------
  |  Branch (5147:6): [True: 498, False: 58]
  ------------------
 5148|    498|		goto err;
 5149|       |
 5150|       |	/* the object is now cached, see what we have */
 5151|     58|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5152|    556|err:
 5153|    556|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    556|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    556|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    556|	int _ret = r; \
  |  |  |  |  155|    556|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 556, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    556|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    549|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 549, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|    556|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    556|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    556|	return _ret; \
  |  |  |  |  163|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5154|    556|}
card-piv.c:piv_parse_ccc:
 5075|     58|{
 5076|     58|	int r = 0;
 5077|     58|	const u8 *body;
 5078|     58|	size_t bodylen;
 5079|     58|	unsigned int cla_out, tag_out;
 5080|       |
 5081|     58|	u8 tag;
 5082|     58|	const u8 *end;
 5083|     58|	size_t len;
 5084|       |
 5085|     58|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     58|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5086|       |
 5087|     58|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     58|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     58|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     58|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 58]
  |  |  ------------------
  ------------------
 5088|       |
 5089|     58|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (5089:6): [True: 0, False: 58]
  |  Branch (5089:22): [True: 0, False: 58]
  ------------------
 5090|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 5091|      0|		goto err;
 5092|      0|	}
 5093|       |
 5094|       |	/* Outer layer is a DER tlv */
 5095|     58|	body = rbuf;
 5096|     58|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    116|#define SC_SUCCESS				0
  ------------------
  |  Branch (5096:6): [True: 0, False: 58]
  ------------------
 5097|     58|			body == NULL ||
  ------------------
  |  Branch (5097:4): [True: 0, False: 58]
  ------------------
 5098|     58|			bodylen == 0 ||
  ------------------
  |  Branch (5098:4): [True: 2, False: 56]
  ------------------
 5099|     56|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (5099:4): [True: 0, False: 56]
  ------------------
 5100|      2|		sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5101|      2|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5102|      2|		goto err;
 5103|      2|	}
 5104|       |
 5105|     56|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  170|     56|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5106|       |
 5107|       |	/* CCC  entries are simple tlv */
 5108|     56|	end = body + bodylen;
 5109|  4.44k|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5109:9): [True: 4.43k, False: 7]
  ------------------
 5110|  4.43k|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len);
 5111|  4.43k|		if (r < 0)
  ------------------
  |  Branch (5111:7): [True: 49, False: 4.38k]
  ------------------
 5112|     49|			goto err;
 5113|  4.38k|		switch (tag) {
  ------------------
  |  Branch (5113:11): [True: 398, False: 3.98k]
  ------------------
 5114|    240|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  176|    240|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5114:3): [True: 240, False: 4.14k]
  ------------------
 5115|    240|			if (len == 0x15) {
  ------------------
  |  Branch (5115:8): [True: 145, False: 95]
  ------------------
 5116|    145|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5116:9): [True: 18, False: 127]
  ------------------
 5117|     18|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  171|     18|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5118|    127|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5118:14): [True: 38, False: 89]
  ------------------
 5119|     38|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  172|     38|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5120|    145|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5120:9): [True: 16, False: 129]
  ------------------
 5121|     16|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  173|     16|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5122|    145|			}
 5123|    240|			break;
 5124|    158|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  177|    158|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5124:3): [True: 158, False: 4.22k]
  ------------------
 5125|    158|			if (len == 0x10) {
  ------------------
  |  Branch (5125:8): [True: 59, False: 99]
  ------------------
 5126|     59|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5126:9): [True: 23, False: 36]
  ------------------
 5127|     23|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  174|     23|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5128|     59|			}
 5129|    158|			break;
 5130|  4.38k|		}
 5131|  4.38k|	}
 5132|       |
 5133|     58|err:
 5134|     58|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     58|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     58|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     58|	int _ret = r; \
  |  |  |  |  155|     58|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 58, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     58|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     51|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 51, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5135|     58|}
card-piv.c:piv_init:
 6012|    724|{
 6013|    724|	int r = 0;
 6014|    724|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    724|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6015|    724|	unsigned long flags;
 6016|    724|	unsigned long flags_eddsa;
 6017|    724|	unsigned long flags_xeddsa;
 6018|    724|	unsigned long ext_flags;
 6019|       |
 6020|    724|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    724|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    724|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    724|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 724]
  |  |  ------------------
  ------------------
 6021|       |
 6022|    724|	r = sc_lock(card); /* hold until match or init is complete */
 6023|    724|	LOG_TEST_RET(card->ctx, r, "sc_lock failed");
  ------------------
  |  |  174|    724|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    724|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    724|	int _ret = (r); \
  |  |  |  |  168|    724|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 724]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    724|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 724]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6024|       |
 6025|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 6026|    724|	if (priv == NULL) {
  ------------------
  |  Branch (6026:6): [True: 0, False: 724]
  ------------------
 6027|      0|		r = piv_match_card_continued(card);
 6028|      0|		priv = PIV_DATA(card);
  ------------------
  |  |  440|      0|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6029|      0|		if (r < 0 || !priv) {
  ------------------
  |  Branch (6029:7): [True: 0, False: 0]
  |  Branch (6029:16): [True: 0, False: 0]
  ------------------
 6030|      0|			sc_log(card->ctx, "piv_match_card_continued failed card->type:%d", card->type);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6031|      0|			sc_unlock(card);
 6032|      0|			piv_finish(card);
 6033|       |			/* tell sc_connect_card to try other driver */
 6034|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6035|      0|		}
 6036|      0|	}
 6037|       |
 6038|       |	/* read "card_driver PIV-II" opensc.conf options, and env parameters */
 6039|    724|	piv_load_options(card);
 6040|       |
 6041|    724|	priv->pstate = PIV_STATE_INIT;
 6042|       |
 6043|    724|	sc_log(card->ctx, "Max send = %zu recv = %zu card->type:%d, CI:%08x AI:%08x",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6044|    724|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 6045|    724|	card->cla = 0x00;
 6046|    724|	if (card->name == NULL)
  ------------------
  |  Branch (6046:6): [True: 724, False: 0]
  ------------------
 6047|    724|		card->name = card->driver->name;
 6048|       |
 6049|    724|	priv->enumtag = piv_aids[0].enumtag;
 6050|       |
 6051|       |	/* PKCS#11 may try to generate session keys, and get confused
 6052|       |	 * if SC_ALGORITHM_ONBOARD_KEY_GEN is present
 6053|       |	 * piv-tool can still do this, just don't tell PKCS#11
 6054|       |	 */
 6055|       |
 6056|    724|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    724|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 6057|       |
 6058|    724|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (6058:6): [True: 0, False: 724]
  ------------------
 6059|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 6060|      0|	}
 6061|       |
 6062|    724|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  600|    724|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (6062:6): [True: 723, False: 1]
  ------------------
 6063|    723|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 6064|       |
 6065|    724|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  601|    724|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (6065:6): [True: 723, False: 1]
  ------------------
 6066|    723|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 6067|       |
 6068|    724|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  602|    724|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (6068:6): [True: 722, False: 2]
  ------------------
 6069|    722|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 6070|       |
 6071|    724|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  603|    724|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (6071:6): [True: 32, False: 692]
  ------------------
 6072|     32|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 6073|       |
 6074|    724|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  597|    724|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (6074:6): [True: 724, False: 0]
  ------------------
 6075|    724|		int i;
 6076|    724|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|    724|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|    724|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|    724|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    724|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 6077|    724|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    724|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    724|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 6078|    724|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  188|    724|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 6079|    724|		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  189|    724|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
              		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  173|    724|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 6080|       |
 6081|  3.62k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (6081:15): [True: 2.89k, False: 724]
  ------------------
 6082|  2.89k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|  2.89k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (6082:8): [True: 1.44k, False: 1.44k]
  ------------------
 6083|  1.44k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  596|  2.89k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (6083:11): [True: 128, False: 1.32k]
  |  Branch (6083:46): [True: 64, False: 64]
  ------------------
 6084|  1.38k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 6085|  1.44k|			}
 6086|       |
 6087|  1.44k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  606|  2.89k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|     48|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (6087:13): [True: 48, False: 1.40k]
  |  Branch (6087:41): [True: 24, False: 24]
  ------------------
 6088|     24|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 6089|       |
 6090|  1.42k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  607|  2.84k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     25|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (6090:13): [True: 25, False: 1.39k]
  |  Branch (6090:42): [True: 24, False: 1]
  ------------------
 6091|     24|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 6092|  2.89k|		}
 6093|    724|	}
 6094|       |
 6095|    724|	if (!(priv->card_issues & CI_NO_RANDOM))
  ------------------
  |  |  587|    724|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (6095:6): [True: 715, False: 9]
  ------------------
 6096|    715|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    715|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 6097|       |
 6098|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6099|    724|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    724|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 6100|       |
 6101|       |	/*
 6102|       |	 * 800-73-3 cards may have discovery. "piv-like cards may or may not.
 6103|       |	 * 800-73-4 with VCI must have it as it has the pin policy needed for VCI .
 6104|       |	 */
 6105|       |
 6106|       |#ifdef ENABLE_PIV_SM
 6107|       |	/*
 6108|       |	 * 800-73-4
 6109|       |	 * Response of AID says if SM is supported. Look for Cipher Suite
 6110|       |	 */
 6111|       |	if (priv->csID && priv->cs != NULL) {
 6112|       |		/*
 6113|       |		 * Main point in SM and VCI is to allow contactless access
 6114|       |		 */
 6115|       |		/* Only piv_init and piv_reader_lock_obtained should call piv_sm_open */
 6116|       |
 6117|       |		/* If user said PIV_SM_FLAGS_NEVER, dont start SM; implies limited contatless access */
 6118|       |		if (priv->sm_flags & PIV_SM_FLAGS_NEVER) {
 6119|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_NEVER");
 6120|       |			r = SC_SUCCESS; /* Users choice */
 6121|       |
 6122|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6123|       |				!(priv->pin_policy & PIV_PP_VCI_IMPL)) {
 6124|       |			sc_log(card->ctx, "Contactless and no card support for VCI");
 6125|       |			r = SC_SUCCESS; /* User should know VCI is not possible with their card; use like 800-73-3 contactless  */
 6126|       |
 6127|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6128|       |				!(priv->pin_policy & PIV_PP_VCI_WITHOUT_PC) &&
 6129|       |				(priv->pairing_code[0] == 0x00)) {
 6130|       |			sc_log(card->ctx, "Contactless, pairing_code required and no pairing code");
 6131|       |			r = SC_ERROR_PIN_CODE_INCORRECT; /* User should know they need to set pairing code */
 6132|       |
 6133|       |		} else {
 6134|       |			priv->sm_flags |= PIV_SM_FLAGS_DEFER_OPEN; /* tell priv_sm_open, OK to open */
 6135|       |			r = piv_sm_open(card);
 6136|       |			sc_log(card->ctx, "piv_sm_open returned:%d", r);
 6137|       |		}
 6138|       |
 6139|       |		/* If failed, and user said PIV_SM_FLAGS_ALWAYS quit */
 6140|       |		if (priv->sm_flags & PIV_SM_FLAGS_ALWAYS && r < 0) {
 6141|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_ALWAYS, SM has failed to start, don't use the card");
 6142|       |			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ALLOWED);
 6143|       |		}
 6144|       |
 6145|       |		/* user has wrong or no required pairing code */
 6146|       |		if (r == SC_ERROR_PIN_CODE_INCORRECT)
 6147|       |			LOG_FUNC_RETURN(card->ctx, r);
 6148|       |
 6149|       |		/* If SM did not start, or is not expected to start, continue on without it */
 6150|       |	}
 6151|       |#endif /* ENABLE_PIV_SM */
 6152|       |
 6153|       |	/*
 6154|       |	 * 800-73-3 cards may have a history object
 6155|       |	 * We want to process it now as this has information on what
 6156|       |	 * keys and certs. "piv like" cards may or may not have history
 6157|       |	 */
 6158|    724|	piv_process_history(card);
 6159|       |
 6160|    724|	priv->pstate = PIV_STATE_NORMAL;
 6161|    724|	sc_unlock(card);
 6162|    724|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    724|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    724|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    724|	int _ret = r; \
  |  |  |  |  155|    724|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 724, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    724|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 724]
  |  |  |  |  ------------------
  |  |  |  |  157|    724|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    724|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    724|	return _ret; \
  |  |  |  |  163|    724|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6163|    724|}
card-piv.c:piv_load_options:
 1686|    724|{
 1687|    724|	int r;
 1688|    724|	size_t i, j;
 1689|    724|	scconf_block **found_blocks, *block;
 1690|       |
 1691|       |#ifdef ENABLE_PIV_SM
 1692|       |	piv_private_data_t *priv = PIV_DATA(card);
 1693|       |	const char *option = NULL;
 1694|       |	int piv_pairing_code_found = 0;
 1695|       |	int piv_use_sm_found = 0;
 1696|       |
 1697|       |	/* pairing code is 8 decimal digits and is card specific */
 1698|       |	if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
 1699|       |		sc_log(card->ctx, "getenv(\"PIV_PAIRING_CODE\") found");
 1700|       |		if (piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1701|       |			memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1702|       |			piv_pairing_code_found = 1;
 1703|       |		}
 1704|       |	}
 1705|       |
 1706|       |	if ((option = getenv("PIV_USE_SM")) != NULL) {
 1707|       |		sc_log(card->ctx, "getenv(\"PIV_USE_SM\")=\"%s\"", option);
 1708|       |		if (!strcmp(option, "never")) {
 1709|       |			priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1710|       |			piv_use_sm_found = 1;
 1711|       |		} else if (!strcmp(option, "always")) {
 1712|       |			priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1713|       |			piv_use_sm_found = 1;
 1714|       |		} else {
 1715|       |			sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1716|       |		}
 1717|       |	}
 1718|       |#endif
 1719|       |
 1720|  1.44k|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (1720:14): [True: 724, False: 724]
  ------------------
 1721|    724|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
 1722|    724|				"card_driver", "PIV-II");
 1723|    724|		if (!found_blocks)
  ------------------
  |  Branch (1723:7): [True: 0, False: 724]
  ------------------
 1724|      0|			continue;
 1725|       |
 1726|    724|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (1726:40): [True: 0, False: 724]
  ------------------
 1727|       |
 1728|       |#ifdef ENABLE_PIV_SM
 1729|       |			/*
 1730|       |			 * "piv_use_sm" if card supports NIST sp800-73-4 sm, when should it be used
 1731|       |			 * never - use card like 800-73-3, i.e. contactless is very limited on
 1732|       |			 * true PIV cards. Some  PIV-like" card may allow this.
 1733|       |			 * this security risk
 1734|       |			 * always - Use even for contact interface.
 1735|       |			 * PINS, crypto and reading of object will not show up in logs
 1736|       |			 * or over network.
 1737|       |			 */
 1738|       |
 1739|       |			if (piv_use_sm_found == 0) {
 1740|       |				option = scconf_get_str(block, "piv_use_sm", "default");
 1741|       |				sc_log(card->ctx, "conf: \"piv_use_sm\"=\"%s\"", option);
 1742|       |				if (!strcmp(option, "default")) {
 1743|       |					/* no new flags */
 1744|       |				} else if (!strcmp(option, "never")) {
 1745|       |					priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1746|       |				} else if (!strcmp(option, "always")) {
 1747|       |					priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1748|       |				} else {
 1749|       |					sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1750|       |				}
 1751|       |			}
 1752|       |
 1753|       |			/* This is really a card specific value and should not be in the conf file */
 1754|       |			if (piv_pairing_code_found == 0) {
 1755|       |				option = scconf_get_str(block, "piv_pairing_code", NULL);
 1756|       |				if (option && piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1757|       |					memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1758|       |				}
 1759|       |			}
 1760|       |#endif
 1761|      0|		}
 1762|    724|		free(found_blocks);
 1763|    724|	}
 1764|    724|	r = SC_SUCCESS;
  ------------------
  |  |   28|    724|#define SC_SUCCESS				0
  ------------------
 1765|    724|	return r;
 1766|    724|}
card-piv.c:piv_process_history:
 5211|    724|{
 5212|    724|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    724|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5213|    724|	int r;
 5214|    724|	int i, tmplen, tmplen2, tmplen3;
 5215|    724|	int enumtag;
 5216|    724|	u8 *rbuf = NULL;
 5217|    724|	size_t rbuflen = 0;
 5218|    724|	const u8 *body;
 5219|    724|	size_t bodylen;
 5220|    724|	const u8 *num;
 5221|    724|	size_t numlen;
 5222|    724|	const u8 *url = NULL;
 5223|    724|	size_t urllen;
 5224|    724|	u8 *ocfhfbuf = NULL;
 5225|    724|	unsigned int cla_out, tag_out;
 5226|    724|	size_t ocfhflen;
 5227|    724|	const u8 *seq;
 5228|    724|	const u8 *seqtag;
 5229|    724|	size_t seqlen;
 5230|    724|	const u8 *keyref;
 5231|    724|	size_t keyreflen;
 5232|    724|	const u8 *cert;
 5233|    724|	size_t certlen;
 5234|    724|	size_t certobjlen, i2;
 5235|    724|	u8 *certobj;
 5236|    724|	u8 *cp;
 5237|       |
 5238|    724|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    724|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    724|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    724|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 724]
  |  |  ------------------
  ------------------
 5239|       |
 5240|    724|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5241|    724|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    724|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5241:6): [True: 103, False: 621]
  ------------------
 5242|    103|		r = 0; /* OK if not found */
 5243|    724|	if (r <= 0) {
  ------------------
  |  Branch (5243:6): [True: 591, False: 133]
  ------------------
 5244|    591|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|    591|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5245|    591|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5246|    591|	}
 5247|       |
 5248|       |	/* the object is now cached, see what we have */
 5249|    133|	if (rbuflen != 0) {
  ------------------
  |  Branch (5249:6): [True: 133, False: 0]
  ------------------
 5250|    133|		body = rbuf;
 5251|    133|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    266|#define SC_SUCCESS				0
  ------------------
  |  Branch (5251:7): [True: 0, False: 133]
  ------------------
 5252|    133|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5252:5): [True: 0, False: 133]
  ------------------
 5253|      0|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5254|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5255|      0|			goto err;
 5256|      0|		}
 5257|       |
 5258|    133|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5258:7): [True: 133, False: 0]
  |  Branch (5258:23): [True: 128, False: 5]
  ------------------
 5259|    128|			numlen = 0;
 5260|    128|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5261|    128|			if (num) {
  ------------------
  |  Branch (5261:8): [True: 48, False: 80]
  ------------------
 5262|     48|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5262:9): [True: 1, False: 47]
  |  Branch (5262:24): [True: 1, False: 46]
  ------------------
 5263|      2|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5264|      2|					goto err;
 5265|      2|				}
 5266|       |
 5267|     46|				priv->keysWithOnCardCerts = *num;
 5268|     46|			}
 5269|       |
 5270|    126|			numlen = 0;
 5271|    126|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5272|    126|			if (num) {
  ------------------
  |  Branch (5272:8): [True: 3, False: 123]
  ------------------
 5273|      3|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5273:9): [True: 1, False: 2]
  |  Branch (5273:24): [True: 1, False: 1]
  ------------------
 5274|      2|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5275|      2|					goto err;
 5276|      2|				}
 5277|       |
 5278|      1|				priv->keysWithOffCardCerts = *num;
 5279|      1|			}
 5280|       |
 5281|    124|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5282|    124|			if (url) {
  ------------------
  |  Branch (5282:8): [True: 73, False: 51]
  ------------------
 5283|     73|				if (urllen > 118) {
  ------------------
  |  Branch (5283:9): [True: 0, False: 73]
  ------------------
 5284|      0|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5285|      0|					goto err;
 5286|      0|				}
 5287|     73|				priv->offCardCertURL = calloc(1, urllen + 1);
 5288|     73|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5288:9): [True: 0, False: 73]
  ------------------
 5289|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5290|     73|				memcpy(priv->offCardCertURL, url, urllen);
 5291|     73|			}
 5292|    124|		} else {
 5293|      5|			sc_log(card->ctx, "Problem with History object\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5294|      5|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
 5295|      5|			goto err;
 5296|      5|		}
 5297|    133|	}
 5298|    124|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   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: 73, False: 51]
  |  |  ------------------
  ------------------
 5299|    124|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5300|    124|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5301|       |
 5302|       |	/* now mark what objects are on the card */
 5303|    851|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5303:14): [True: 727, False: 124]
  ------------------
 5304|    727|		priv->obj_cache[PIV_OBJ_RETIRED_X509_1 + i].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|    851|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5305|       |
 5306|       |	/*
 5307|       |	 * If user has gotten copy of the file from the offCardCertsURL,
 5308|       |	 * we will read in and add the certs to the cache as listed on
 5309|       |	 * the card. some of the certs may be on the card as well.
 5310|       |	 *
 5311|       |	 * Get file name from url. verify that the filename is valid
 5312|       |	 * The URL ends in a SHA-256 string. We will use this as the filename
 5313|       |	 * in the directory used for the  PKCS15 cache
 5314|       |	 * "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
 5315|       |	 */
 5316|       |
 5317|    124|	r = 0;
 5318|    124|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5318:6): [True: 73, False: 51]
  ------------------
 5319|     73|		char *fp;
 5320|     73|		char filename[PATH_MAX];
 5321|       |
 5322|     73|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5322:7): [True: 72, False: 1]
  ------------------
 5323|     72|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     72|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5324|     72|			goto err;
 5325|     72|		}
 5326|       |		/* find the last /  so we have the filename part */
 5327|      1|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5328|      1|		if (fp == NULL) {
  ------------------
  |  Branch (5328:7): [True: 1, False: 0]
  ------------------
 5329|      1|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5330|      1|			goto err;
 5331|      1|		}
 5332|      0|		fp++;
 5333|      0|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5333:7): [True: 0, False: 0]
  ------------------
 5334|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5335|      0|			goto err;
 5336|      0|		}
 5337|      0|		for (i = 0; i < 64; i++) {
  ------------------
  |  Branch (5337:15): [True: 0, False: 0]
  ------------------
 5338|      0|			if (isxdigit((unsigned char)fp[i]) == 0) {
  ------------------
  |  Branch (5338:8): [True: 0, False: 0]
  ------------------
 5339|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5340|      0|				goto err;
 5341|      0|			}
 5342|      0|		}
 5343|       |
 5344|       |		/* Use the same directory as used for other OpenSC cached items */
 5345|      0|		r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);
 5346|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5346:7): [True: 0, False: 0]
  ------------------
 5347|      0|			goto err;
 5348|       |#ifdef _WIN32
 5349|       |		strlcat(filename, "\\", PATH_MAX);
 5350|       |#else
 5351|      0|		strlcat(filename, "/", PATH_MAX);
 5352|      0|#endif
 5353|      0|		strlcat(filename, fp, PATH_MAX);
 5354|       |
 5355|      0|		r = piv_read_obj_from_file(card, filename,
 5356|      0|				&ocfhfbuf, &ocfhflen);
 5357|      0|		if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5357:7): [True: 0, False: 0]
  ------------------
 5358|      0|			r = 0;
 5359|      0|			goto err;
 5360|      0|		}
 5361|       |
 5362|       |		/*
 5363|       |		 * Its a seq of seq of a key ref and cert
 5364|       |		 */
 5365|       |
 5366|      0|		body = ocfhfbuf;
 5367|      0|		if (sc_asn1_read_tag(&body, ocfhflen, &cla_out, &tag_out, &bodylen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5367:7): [True: 0, False: 0]
  ------------------
 5368|      0|				body == NULL ||
  ------------------
  |  Branch (5368:5): [True: 0, False: 0]
  ------------------
 5369|      0|				bodylen == 0 ||
  ------------------
  |  Branch (5369:5): [True: 0, False: 0]
  ------------------
 5370|      0|				(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5370:5): [True: 0, False: 0]
  ------------------
 5371|      0|			sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5372|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5373|      0|			goto err;
 5374|      0|		}
 5375|      0|		seq = body;
 5376|      0|		while (bodylen > 0) {
  ------------------
  |  Branch (5376:10): [True: 0, False: 0]
  ------------------
 5377|      0|			seqtag = seq;
 5378|      0|			if (sc_asn1_read_tag(&seq, bodylen, &cla_out, &tag_out, &seqlen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5378:8): [True: 0, False: 0]
  ------------------
 5379|      0|					seq == 0 ||
  ------------------
  |  Branch (5379:6): [True: 0, False: 0]
  ------------------
 5380|      0|					seqlen == 0 ||
  ------------------
  |  Branch (5380:6): [True: 0, False: 0]
  ------------------
 5381|      0|					(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5381:6): [True: 0, False: 0]
  ------------------
 5382|      0|				sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5383|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5384|      0|				goto err;
 5385|      0|			}
 5386|      0|			keyref = sc_asn1_find_tag(card->ctx, seq, seqlen, 0x04, &keyreflen);
 5387|      0|			if (!keyref || keyreflen != 1 ||
  ------------------
  |  Branch (5387:8): [True: 0, False: 0]
  |  Branch (5387:19): [True: 0, False: 0]
  ------------------
 5388|      0|					(*keyref < 0x82 || *keyref > 0x95)) {
  ------------------
  |  Branch (5388:7): [True: 0, False: 0]
  |  Branch (5388:25): [True: 0, False: 0]
  ------------------
 5389|      0|				sc_log(card->ctx, "DER problem");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5390|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5391|      0|				goto err;
 5392|      0|			}
 5393|      0|			cert = keyref + keyreflen;
 5394|      0|			certlen = seqlen - (cert - seq);
 5395|       |
 5396|      0|			enumtag = PIV_OBJ_RETIRED_X509_1 + *keyref - 0x82;
 5397|       |			/* now add the cert like another object */
 5398|       |
 5399|      0|			if ((tmplen = sc_asn1_put_tag(0x70, NULL, certlen, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5399:8): [True: 0, False: 0]
  ------------------
 5400|      0|					(tmplen2 = sc_asn1_put_tag(0x71, NULL, 1, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5400:6): [True: 0, False: 0]
  ------------------
 5401|      0|					(tmplen3 = sc_asn1_put_tag(0xFE, NULL, 0, NULL, 0, NULL)) <= 0) {
  ------------------
  |  Branch (5401:6): [True: 0, False: 0]
  ------------------
 5402|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5403|      0|				goto err;
 5404|      0|			}
 5405|      0|			i2 = tmplen + tmplen2 + tmplen3;
 5406|      0|			tmplen = sc_asn1_put_tag(0x53, NULL, i2, NULL, 0, NULL);
 5407|      0|			if (tmplen <= 0) {
  ------------------
  |  Branch (5407:8): [True: 0, False: 0]
  ------------------
 5408|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5409|      0|				goto err;
 5410|      0|			}
 5411|       |
 5412|      0|			certobjlen = tmplen;
 5413|      0|			certobj = malloc(certobjlen);
 5414|      0|			if (certobj == NULL) {
  ------------------
  |  Branch (5414:8): [True: 0, False: 0]
  ------------------
 5415|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 5416|      0|				goto err;
 5417|      0|			}
 5418|      0|			cp = certobj;
 5419|      0|			if ((r = sc_asn1_put_tag(0x53, NULL, i2, cp, certobjlen, &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5419:8): [True: 0, False: 0]
  ------------------
 5420|      0|					(r = sc_asn1_put_tag(0x70, cert, certlen, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5420:6): [True: 0, False: 0]
  ------------------
 5421|      0|					(r = sc_asn1_put_tag(0x71, NULL, 1, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5421:6): [True: 0, False: 0]
  ------------------
 5422|      0|				goto err;
 5423|      0|			}
 5424|      0|			*cp++ = 0x00;
 5425|      0|			r = sc_asn1_put_tag(0xFE, NULL, 0, cp, certobjlen - (cp - certobj), &cp);
 5426|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5426:8): [True: 0, False: 0]
  ------------------
 5427|      0|				goto err;
 5428|      0|			}
 5429|       |
 5430|      0|			priv->obj_cache[enumtag].obj_data = certobj;
 5431|      0|			priv->obj_cache[enumtag].obj_len = certobjlen;
 5432|      0|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|      0|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 5433|      0|			priv->obj_cache[enumtag].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5434|       |
 5435|      0|			r = piv_cache_internal_data(card, enumtag);
 5436|      0|			sc_log(card->ctx, "got internal r=%d", r);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5437|       |
 5438|      0|			sc_log(card->ctx, "Added from off card file #%d %p:%zu 0x%02X",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5439|      0|					enumtag,
 5440|      0|					priv->obj_cache[enumtag].obj_data,
 5441|      0|					priv->obj_cache[enumtag].obj_len, *keyref);
 5442|       |
 5443|      0|			bodylen -= (seqlen + seq - seqtag);
 5444|      0|			seq += seqlen;
 5445|      0|		}
 5446|      0|	}
 5447|    724|err:
 5448|    724|	if (ocfhfbuf)
  ------------------
  |  Branch (5448:6): [True: 0, False: 724]
  ------------------
 5449|      0|		free(ocfhfbuf);
 5450|    724|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    724|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    724|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    724|	int _ret = r; \
  |  |  |  |  155|    724|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 724, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    724|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    565|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 565, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  157|    724|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    724|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    724|	return _ret; \
  |  |  |  |  163|    724|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5451|    724|}
card-piv.c:piv_cache_internal_data:
 3285|  1.14k|{
 3286|  1.14k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.14k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3287|  1.14k|	const u8 *tag;
 3288|  1.14k|	const u8 *body;
 3289|  1.14k|	size_t taglen;
 3290|  1.14k|	size_t bodylen;
 3291|  1.14k|	int compressed = 0;
 3292|  1.14k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.14k|#define SC_SUCCESS				0
  ------------------
 3293|       |#ifdef ENABLE_PIV_SM
 3294|       |	u8 *cvc_start = NULL;
 3295|       |	size_t cvc_len = 0;
 3296|       |#endif
 3297|       |
 3298|       |	/* if already cached */
 3299|  1.14k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3299:6): [True: 502, False: 642]
  |  Branch (3299:52): [True: 502, False: 0]
  ------------------
 3300|    502|		sc_log(card->ctx, "#%d found internal %p:%zu",
  ------------------
  |  |   71|    502|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3301|    502|				enumtag,
 3302|    502|				priv->obj_cache[enumtag].internal_obj_data,
 3303|    502|				priv->obj_cache[enumtag].internal_obj_len);
 3304|    502|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    502|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    502|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    502|	int _ret = r; \
  |  |  |  |  155|    502|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 502, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    502|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 502]
  |  |  |  |  ------------------
  |  |  |  |  157|    502|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    502|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    502|	return _ret; \
  |  |  |  |  163|    502|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3305|    502|	}
 3306|       |
 3307|    642|	body = sc_asn1_find_tag(card->ctx,
 3308|    642|			priv->obj_cache[enumtag].obj_data,
 3309|    642|			priv->obj_cache[enumtag].obj_len,
 3310|    642|			0x53, &bodylen);
 3311|       |
 3312|    642|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3312:6): [True: 0, False: 642]
  |  Branch (3312:22): [True: 0, False: 642]
  ------------------
 3313|    642|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3314|       |
 3315|       |	/* get the certificate out */
 3316|    642|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  644|    642|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3316:6): [True: 642, False: 0]
  ------------------
 3317|       |
 3318|    642|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x71, &taglen);
 3319|       |		/* 800-72-1 not clear if this is 80 or 01 Sent comment to NIST for 800-72-2 */
 3320|       |		/* 800-73-3 says it is 01, keep dual test so old cards still work */
 3321|    642|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3321:7): [True: 126, False: 516]
  |  Branch (3321:14): [True: 115, False: 11]
  |  Branch (3321:29): [True: 12, False: 103]
  |  Branch (3321:48): [True: 14, False: 89]
  ------------------
 3322|     26|			compressed = 1;
 3323|       |
 3324|       |#ifdef ENABLE_PIV_SM
 3325|       |		cvc_start = (u8 *)tag + taglen; /* save for later as cvs (if present) follows  0x71 */
 3326|       |#endif
 3327|       |
 3328|    642|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3329|    642|		if (tag == NULL)
  ------------------
  |  Branch (3329:7): [True: 130, False: 512]
  ------------------
 3330|    642|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|    130|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    130|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    130|	int _ret = r; \
  |  |  |  |  155|    130|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 130, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    130|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    130|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 130, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    130|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    130|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    130|	return _ret; \
  |  |  |  |  163|    130|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3331|       |
 3332|    512|		if (taglen == 0)
  ------------------
  |  Branch (3332:7): [True: 10, False: 502]
  ------------------
 3333|    512|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3334|       |
 3335|    502|		if (compressed) {
  ------------------
  |  Branch (3335:7): [True: 6, False: 496]
  ------------------
 3336|      6|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  152|      6|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3337|      6|		}
 3338|       |		/* internal certificate remains compressed */
 3339|    502|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3339:7): [True: 0, False: 502]
  ------------------
 3340|    502|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3341|       |
 3342|    502|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3343|    502|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3344|       |
 3345|       |#ifdef ENABLE_PIV_SM
 3346|       |		/* PIV_OBJ_SM_CERT_SIGNER  CERT OBJECT may also have a intermediate CVC */
 3347|       |		if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CVC) {
 3348|       |			/* cvc if present should be at cvc_start.
 3349|       |			 * find the tag(T) and get value(V) and len(L) from TLV.
 3350|       |			 * Could reconstruct ASN1 of (T)(L) stating location from length and known tag.
 3351|       |			 * as the size of (L) depends on the length of value
 3352|       |			 */
 3353|       |			if ((tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x7F21, &taglen)) != NULL &&
 3354|       |					cvc_start &&
 3355|       |					cvc_start < tag &&
 3356|       |					cvc_start[0] == 0x7f && cvc_start[1] == 0x21) {
 3357|       |				cvc_len = tag - cvc_start + taglen;
 3358|       |				/* decode the intermediate CVC */
 3359|       |				r = piv_decode_cvc(card, &cvc_start, &cvc_len, &priv->sm_in_cvc);
 3360|       |				if (r < 0) {
 3361|       |					sc_log(card->ctx, "unable to parse intermediate CVC: %d skipping", r);
 3362|       |				}
 3363|       |				priv->sm_flags |= PIV_SM_FLAGS_SM_IN_CVC_PRESENT;
 3364|       |			}
 3365|       |		}
 3366|       |#endif /* ENABLE_PIV_SM */
 3367|       |
 3368|       |		/* convert pub key to internal */
 3369|    502|	} else if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  645|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3369:13): [True: 0, False: 0]
  ------------------
 3370|      0|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, *body, &taglen);
 3371|      0|		if (tag == NULL)
  ------------------
  |  Branch (3371:7): [True: 0, False: 0]
  ------------------
 3372|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3373|       |
 3374|      0|		if (taglen == 0)
  ------------------
  |  Branch (3374:7): [True: 0, False: 0]
  ------------------
 3375|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3376|       |
 3377|      0|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3377:7): [True: 0, False: 0]
  ------------------
 3378|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3379|       |
 3380|      0|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3381|      0|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3382|      0|	} else {
 3383|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3384|      0|	}
 3385|       |
 3386|    502|	sc_log(card->ctx, "added #%d internal %p:%zu",
  ------------------
  |  |   71|    502|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3387|    502|			enumtag,
 3388|    502|			priv->obj_cache[enumtag].internal_obj_data,
 3389|    502|			priv->obj_cache[enumtag].internal_obj_len);
 3390|       |
 3391|    502|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    502|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    502|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    502|	int _ret = r; \
  |  |  |  |  155|    502|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 502, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    502|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 502]
  |  |  |  |  ------------------
  |  |  |  |  157|    502|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    502|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    502|	return _ret; \
  |  |  |  |  163|    502|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3392|    502|}
card-piv.c:piv_finish:
 5474|  9.32k|{
 5475|  9.32k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  9.32k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5476|  9.32k|	int i;
 5477|       |
 5478|  9.32k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.32k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.32k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.32k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.32k]
  |  |  ------------------
  ------------------
 5479|  9.32k|	if (priv) {
  ------------------
  |  Branch (5479:6): [True: 5.02k, False: 4.29k]
  ------------------
 5480|  5.02k|		if (priv->context_specific) {
  ------------------
  |  Branch (5480:7): [True: 4, False: 5.01k]
  ------------------
 5481|      4|			sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC lock");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5482|      4|			priv->context_specific = 0;
 5483|      4|			sc_unlock(card);
 5484|      4|		}
 5485|  5.02k|		free(priv->aid_der.value);
 5486|  5.02k|		free(priv->al_label);
 5487|  5.02k|		if (priv->w_buf)
  ------------------
  |  Branch (5487:7): [True: 0, False: 5.02k]
  ------------------
 5488|      0|			free(priv->w_buf);
 5489|  5.02k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5489:7): [True: 73, False: 4.94k]
  ------------------
 5490|     73|			free(priv->offCardCertURL);
 5491|   306k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5491:15): [True: 301k, False: 5.02k]
  ------------------
 5492|   301k|			piv_obj_cache_free_entry(card, i, 0);
 5493|   301k|		}
 5494|       |#ifdef ENABLE_PIV_SM
 5495|       |		piv_clear_cvc_content(&priv->sm_cvc);
 5496|       |		piv_clear_cvc_content(&priv->sm_in_cvc);
 5497|       |		piv_clear_sm_session(&priv->sm_session);
 5498|       |#endif /* ENABLE_PIV_SM */
 5499|       |
 5500|  5.02k|		free(priv);
 5501|       |		card->drv_data = NULL; /* priv */
 5502|  5.02k|	}
 5503|  9.32k|	return 0;
 5504|  9.32k|}
card-piv.c:piv_select_file:
 4908|  6.04k|{
 4909|  6.04k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  6.04k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4910|  6.04k|	int r;
 4911|  6.04k|	int i;
 4912|  6.04k|	const u8 *path;
 4913|  6.04k|	size_t pathlen;
 4914|  6.04k|	sc_file_t *file = NULL;
 4915|  6.04k|	u8 *rbuf = NULL;
 4916|  6.04k|	size_t rbuflen = 0;
 4917|       |
 4918|  6.04k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.04k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.04k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.04k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.04k]
  |  |  ------------------
  ------------------
 4919|       |
 4920|  6.04k|	path = in_path->value;
 4921|  6.04k|	pathlen = in_path->len;
 4922|       |
 4923|       |	/* only support single EF in current application */
 4924|       |	/*
 4925|       |	 * PIV emulates files, and only does so because sc_pkcs15_* uses
 4926|       |	 * select_file and read_binary. The emulation adds path emulated structures
 4927|       |	 * so piv_select_file will find it.
 4928|       |	 * there is no dir. Only direct access to emulated files
 4929|       |	 * thus opensc-tool and opensc-explorer can not read the emulated files
 4930|       |	 */
 4931|       |
 4932|  6.04k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (4932:6): [True: 1.72k, False: 4.32k]
  ------------------
 4933|  1.72k|		if (pathlen > 2) {
  ------------------
  |  Branch (4933:7): [True: 1.72k, False: 0]
  ------------------
 4934|  1.72k|			path += 2;
 4935|  1.72k|			pathlen -= 2;
 4936|  1.72k|		}
 4937|  1.72k|	}
 4938|       |
 4939|  6.04k|	i = piv_find_obj_by_containerid(card, path);
 4940|       |
 4941|  6.04k|	if (i < 0)
  ------------------
  |  Branch (4941:6): [True: 1.74k, False: 4.30k]
  ------------------
 4942|  6.04k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  1.74k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.74k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.74k|	int _ret = r; \
  |  |  |  |  155|  1.74k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.74k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.74k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.74k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.74k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.74k|	return _ret; \
  |  |  |  |  163|  1.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4943|       |
 4944|       |	/*
 4945|       |	 * pkcs15 will use a 2 byte path or a 4 byte path
 4946|       |	 * with cece added to path to request only the cert from the cert obj
 4947|       |	 * PIV "Container ID" is used as the path, and are two bytes long
 4948|       |	 */
 4949|  4.30k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (4949:28): [True: 4.30k, False: 0]
  |  Branch (4949:44): [True: 4.30k, False: 0]
  |  Branch (4949:63): [True: 4.30k, False: 0]
  ------------------
 4950|       |
 4951|  4.30k|	priv->selected_obj = i;
 4952|  4.30k|	priv->rwb_state = -1;
 4953|       |
 4954|       |	/* make it look like the file was found. */
 4955|       |	/* We don't want to read it now  unless we need the length */
 4956|       |
 4957|  4.30k|	if (file_out) {
  ------------------
  |  Branch (4957:6): [True: 4.30k, False: 0]
  ------------------
 4958|       |		/* we need to read it now, to get length into cache */
 4959|  4.30k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 4960|       |
 4961|  4.30k|		if (r < 0)
  ------------------
  |  Branch (4961:7): [True: 3.66k, False: 642]
  ------------------
 4962|  4.30k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  3.66k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.66k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.66k|	int _ret = r; \
  |  |  |  |  155|  3.66k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.66k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.66k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.66k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.66k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.66k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.66k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.66k|	return _ret; \
  |  |  |  |  163|  3.66k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4963|       |
 4964|       |		/* get the cert or the pub key out and into the cache too */
 4965|    642|		if (priv->return_only_cert || piv_objects[i].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  645|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (4965:7): [True: 642, False: 0]
  |  Branch (4965:33): [True: 0, False: 0]
  ------------------
 4966|    642|			r = piv_cache_internal_data(card, i);
 4967|    642|			if (r < 0)
  ------------------
  |  Branch (4967:8): [True: 140, False: 502]
  ------------------
 4968|    642|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    140|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    140|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    140|	int _ret = r; \
  |  |  |  |  155|    140|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 140, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    140|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    140|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 140, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    140|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    140|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    140|	return _ret; \
  |  |  |  |  163|    140|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4969|    642|		}
 4970|       |
 4971|    502|		file = sc_file_new();
 4972|    502|		if (file == NULL)
  ------------------
  |  Branch (4972:7): [True: 0, False: 502]
  ------------------
 4973|    502|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4974|       |
 4975|    502|		file->path = *in_path;
 4976|       |		/* this could be like the FCI */
 4977|    502|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    502|#define SC_FILE_TYPE_DF			0x04
  ------------------
 4978|    502|		file->shareable = 0;
 4979|    502|		file->ef_structure = 0;
 4980|    502|		if (priv->return_only_cert)
  ------------------
  |  Branch (4980:7): [True: 502, False: 0]
  ------------------
 4981|    502|			file->size = priv->obj_cache[i].internal_obj_len;
 4982|      0|		else
 4983|      0|			file->size = priv->obj_cache[i].obj_len;
 4984|       |
 4985|    502|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 4986|       |
 4987|    502|		*file_out = file;
 4988|    502|	}
 4989|       |
 4990|    502|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    502|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    502|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    502|	int _ret = r; \
  |  |  |  |  155|    502|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 502, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    502|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 502]
  |  |  |  |  ------------------
  |  |  |  |  157|    502|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    502|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    502|	return _ret; \
  |  |  |  |  163|    502|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4991|    502|}
card-piv.c:piv_find_obj_by_containerid:
 1770|  50.4k|{
 1771|  50.4k|	int i;
 1772|       |
 1773|  50.4k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  50.4k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  50.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  50.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  50.4k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 50.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1774|  50.4k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   71|  50.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__
  |  |  ------------------
  ------------------
 1775|       |
 1776|  1.05M|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1776:14): [True: 1.05M, False: 2.45k]
  ------------------
 1777|  1.05M|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1777:7): [True: 432k, False: 621k]
  |  Branch (1777:50): [True: 47.9k, False: 384k]
  ------------------
 1778|  1.05M|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|  47.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  47.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  47.9k|	int _ret = r; \
  |  |  |  |  155|  47.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 716, False: 47.2k]
  |  |  |  |  ------------------
  |  |  |  |  156|    716|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 716]
  |  |  |  |  ------------------
  |  |  |  |  157|    716|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  47.2k|	} else { \
  |  |  |  |  159|  47.2k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  47.2k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  47.2k|	} \
  |  |  |  |  162|  47.9k|	return _ret; \
  |  |  |  |  163|  47.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|  1.05M|	}
 1780|       |
 1781|  2.45k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  2.45k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.45k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.45k|	int _ret = r; \
  |  |  |  |  155|  2.45k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.45k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.45k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.45k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.45k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.45k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.45k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.45k|	return _ret; \
  |  |  |  |  163|  2.45k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1782|  2.45k|}
card-piv.c:piv_read_binary:
 3401|  1.87k|{
 3402|  1.87k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  1.87k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3403|  1.87k|	int enumtag;
 3404|  1.87k|	int r;
 3405|  1.87k|	u8 *rbuf = NULL;
 3406|  1.87k|	size_t rbuflen = 0;
 3407|  1.87k|	const u8 *body;
 3408|  1.87k|	size_t bodylen;
 3409|       |
 3410|  1.87k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.87k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.87k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.87k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.87k]
  |  |  ------------------
  ------------------
 3411|  1.87k|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3411:6): [True: 0, False: 1.87k]
  ------------------
 3412|  1.87k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3413|  1.87k|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3414|       |
 3415|  1.87k|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3415:6): [True: 502, False: 1.37k]
  ------------------
 3416|    502|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3417|       |
 3418|    502|		if (r >= 0) {
  ------------------
  |  Branch (3418:7): [True: 502, False: 0]
  ------------------
 3419|       |			/* an object with no data will be considered not found */
 3420|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3421|    502|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3421:8): [True: 0, False: 502]
  |  Branch (3421:17): [True: 0, False: 502]
  |  Branch (3421:37): [True: 502, False: 0]
  |  Branch (3421:65): [True: 0, False: 502]
  ------------------
 3422|      0|				r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3423|      0|				goto err;
 3424|      0|			}
 3425|       |
 3426|    502|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3427|    502|			if (body == NULL) {
  ------------------
  |  Branch (3427:8): [True: 0, False: 502]
  ------------------
 3428|       |				/* if missing, assume its the body */
 3429|       |				/* DEE bug in the beta card */
 3430|      0|				sc_log(card->ctx, " ***** tag 0x53 MISSING");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3431|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3432|      0|				goto err;
 3433|      0|			}
 3434|    502|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3434:8): [True: 0, False: 502]
  ------------------
 3435|      0|				sc_log(card->ctx, " ***** tag length > then data: %zu>%zu+%zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3436|      0|						bodylen, body - rbuf, rbuflen);
 3437|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3438|      0|				goto err;
 3439|      0|			}
 3440|       |			/* if cached obj has internal interesting data (cert or pub key) */
 3441|    502|			if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  645|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3441:8): [True: 502, False: 0]
  |  Branch (3441:34): [True: 0, False: 0]
  ------------------
 3442|    502|				r = piv_cache_internal_data(card, enumtag);
 3443|    502|				if (r < 0)
  ------------------
  |  Branch (3443:9): [True: 0, False: 502]
  ------------------
 3444|      0|					goto err;
 3445|    502|			}
 3446|    502|		}
 3447|    502|		priv->rwb_state = 0;
 3448|    502|	}
 3449|       |
 3450|  1.87k|	if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  645|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3450:6): [True: 1.87k, False: 0]
  |  Branch (3450:32): [True: 0, False: 0]
  ------------------
 3451|  1.87k|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3452|  1.87k|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3453|  1.87k|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  152|  1.87k|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3453:7): [True: 27, False: 1.84k]
  |  Branch (3453:70): [True: 27, False: 0]
  ------------------
 3454|     27|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     27|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3455|     27|		}
 3456|  1.87k|	} else {
 3457|      0|		rbuf = priv->obj_cache[enumtag].obj_data;
 3458|      0|		rbuflen = priv->obj_cache[enumtag].obj_len;
 3459|      0|	}
 3460|       |	/* rbuf rbuflen has pointer and length to cached data */
 3461|       |
 3462|  1.87k|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3462:6): [True: 0, False: 1.87k]
  ------------------
 3463|      0|		count = rbuflen - idx;
 3464|  1.87k|	if (count <= 0) {
  ------------------
  |  Branch (3464:6): [True: 0, False: 1.87k]
  ------------------
 3465|      0|		r = 0;
 3466|      0|		priv->rwb_state = 1;
 3467|  1.87k|	} else {
 3468|  1.87k|		memcpy(buf, rbuf + idx, count);
 3469|  1.87k|		r = (int)count;
 3470|  1.87k|	}
 3471|       |
 3472|  1.87k|err:
 3473|  1.87k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.87k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.87k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.87k|	int _ret = r; \
  |  |  |  |  155|  1.87k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1.87k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.87k|	} else { \
  |  |  |  |  159|  1.87k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.87k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.87k|	} \
  |  |  |  |  162|  1.87k|	return _ret; \
  |  |  |  |  163|  1.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3474|  1.87k|}
card-piv.c:piv_set_security_env:
 4669|     44|{
 4670|     44|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     44|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4671|     44|	int r = 0;
 4672|       |
 4673|     44|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     44|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     44|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     44|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 44]
  |  |  ------------------
  ------------------
 4674|       |
 4675|     44|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4676|     44|			env->flags, env->operation, env->algorithm, env->algorithm_flags,
 4677|     44|			env->algorithm_ref, env->key_ref[0], env->key_ref_len);
 4678|       |
 4679|     44|	priv->operation = env->operation;
 4680|     44|	priv->algorithm = env->algorithm;
 4681|       |
 4682|     44|	if (env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|     44|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (4682:6): [True: 15, False: 29]
  ------------------
 4683|     15|		priv->alg_id = 0x06; /* Say it is RSA, set 5, 6, 7 later */
 4684|     29|	} else if (env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|     29|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (4684:13): [True: 29, False: 0]
  ------------------
 4685|     29|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|     29|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (4685:7): [True: 29, False: 0]
  ------------------
 4686|     29|			switch (env->algorithm_ref) {
 4687|     29|			case 256:
  ------------------
  |  Branch (4687:4): [True: 29, False: 0]
  ------------------
 4688|     29|				priv->alg_id = 0x11; /* Say it is EC 256 */
 4689|     29|				priv->key_size = 256;
 4690|     29|				break;
 4691|      0|			case 384:
  ------------------
  |  Branch (4691:4): [True: 0, False: 29]
  ------------------
 4692|      0|				priv->alg_id = 0x14;
 4693|      0|				priv->key_size = 384;
 4694|      0|				break;
 4695|      0|			default:
  ------------------
  |  Branch (4695:4): [True: 0, False: 29]
  ------------------
 4696|      0|				r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4697|     29|			}
 4698|     29|		} else
 4699|      0|			r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4700|     29|	} else if (env->algorithm == SC_ALGORITHM_EDDSA) {
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (4700:13): [True: 0, False: 0]
  ------------------
 4701|      0|		priv->alg_id = 0xE0;
 4702|      0|		priv->key_size = 255;
 4703|      0|	} else if (env->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4703:13): [True: 0, False: 0]
  ------------------
 4704|      0|		priv->alg_id = 0xE1;
 4705|      0|		priv->key_size = 255;
 4706|      0|	} else
 4707|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4708|     44|	priv->key_ref = env->key_ref[0];
 4709|       |
 4710|     44|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     44|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     44|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     44|	int _ret = r; \
  |  |  |  |  155|     44|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 44, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     44|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 44]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4711|     44|}
card-piv.c:piv_compute_signature:
 4839|     31|{
 4840|     31|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     31|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4841|     31|	int r;
 4842|     31|	size_t nLen;
 4843|     31|	u8 rbuf[128]; /* For EC conversions  384 will fit */
 4844|       |
 4845|     31|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     31|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     31|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     31|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 31]
  |  |  ------------------
  ------------------
 4846|       |
 4847|       |	/* The PIV returns a DER SEQUENCE{INTEGER, INTEGER}
 4848|       |	 * Which may have leading 00 to force a positive integer
 4849|       |	 * But PKCS11 just wants 2* field_length in bytes
 4850|       |	 * So we have to strip out the integers
 4851|       |	 * and pad on left if too short.
 4852|       |	 */
 4853|       |
 4854|     31|	if (priv->alg_id == 0x11 || priv->alg_id == 0x14) {
  ------------------
  |  Branch (4854:6): [True: 29, False: 2]
  |  Branch (4854:30): [True: 0, False: 2]
  ------------------
 4855|     29|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  146|     29|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4856|     29|		if (outlen < 2 * nLen) {
  ------------------
  |  Branch (4856:7): [True: 0, False: 29]
  ------------------
 4857|      0|			sc_log(card->ctx, " output too small for EC signature %zu < %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4858|      0|					outlen, 2 * nLen);
 4859|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4860|      0|			goto err;
 4861|      0|		}
 4862|       |
 4863|     29|		r = piv_validate_general_authentication(card, data, datalen, rbuf, sizeof rbuf);
 4864|     29|		if (r < 0)
  ------------------
  |  Branch (4864:7): [True: 27, False: 2]
  ------------------
 4865|     27|			goto err;
 4866|       |
 4867|      2|		r = sc_asn1_decode_ecdsa_signature(card->ctx, rbuf, r, nLen, &out, outlen);
 4868|       |		/* Yubikey 5.7.x supports ED25519 */
 4869|      2|	} else if (priv->alg_id == 0xE0) {
  ------------------
  |  Branch (4869:13): [True: 0, False: 2]
  ------------------
 4870|      0|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  146|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4871|      0|		if (outlen < nLen) {
  ------------------
  |  Branch (4871:7): [True: 0, False: 0]
  ------------------
 4872|      0|			sc_log(card->ctx, " output too small for ED signature %zu < %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4873|      0|					outlen, nLen);
 4874|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4875|      0|			goto err;
 4876|      0|		}
 4877|      0|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4878|       |
 4879|      2|	} else { /* RSA is all set */
 4880|      2|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4881|      2|	}
 4882|       |
 4883|     31|err:
 4884|     31|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     31|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     31|	int _ret = r; \
  |  |  155|     31|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 31, False: 0]
  |  |  ------------------
  |  |  156|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 30, False: 1]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 4885|     31|}
card-piv.c:piv_validate_general_authentication:
 4742|     44|{
 4743|     44|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     44|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4744|     44|	int r, tmplen, tmplen2;
 4745|     44|	u8 *p;
 4746|     44|	const unsigned char *p2;
 4747|     44|	size_t taglen;
 4748|     44|	size_t bodylen;
 4749|     44|	unsigned int cla, tag;
 4750|     44|	unsigned int real_alg_id, op_tag;
 4751|       |
 4752|     44|	u8 sbuf[4096]; /* needs work. for 4096 needs 512+10 or so */
 4753|     44|	size_t sbuflen = sizeof(sbuf);
 4754|     44|	u8 rbuf[4096];
 4755|       |
 4756|     44|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     44|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     44|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     44|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 44]
  |  |  ------------------
  ------------------
 4757|       |
 4758|       |	/* should assume large send data */
 4759|     44|	p = sbuf;
 4760|     44|	tmplen = sc_asn1_put_tag(0xff, NULL, datalen, NULL, 0, NULL);
 4761|     44|	tmplen2 = sc_asn1_put_tag(0x82, NULL, 0, NULL, 0, NULL);
 4762|     44|	if (tmplen <= 0 || tmplen2 <= 0) {
  ------------------
  |  Branch (4762:6): [True: 0, False: 44]
  |  Branch (4762:21): [True: 0, False: 44]
  ------------------
 4763|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4764|      0|	}
 4765|     44|	tmplen += tmplen2;
 4766|     44|	if ((r = sc_asn1_put_tag(0x7c, NULL, tmplen, p, sbuflen, &p)) != SC_SUCCESS ||
  ------------------
  |  |   28|     88|#define SC_SUCCESS				0
  ------------------
  |  Branch (4766:6): [True: 0, False: 44]
  ------------------
 4767|     44|			(r = sc_asn1_put_tag(0x82, NULL, 0, p, sbuflen - (p - sbuf), &p)) != SC_SUCCESS) {
  ------------------
  |  |   28|     44|#define SC_SUCCESS				0
  ------------------
  |  Branch (4767:4): [True: 0, False: 44]
  ------------------
 4768|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4769|      0|	}
 4770|     44|	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   50|     88|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4770:6): [True: 0, False: 44]
  |  Branch (4770:53): [True: 0, False: 0]
  |  Branch (4770:91): [True: 0, False: 0]
  ------------------
 4771|      0|		op_tag = 0x85;
 4772|     44|	} else {
 4773|     44|		op_tag = 0x81;
 4774|     44|	}
 4775|     44|	r = sc_asn1_put_tag(op_tag, data, datalen, p, sbuflen - (p - sbuf), &p);
 4776|     44|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     44|#define SC_SUCCESS				0
  ------------------
  |  Branch (4776:6): [True: 0, False: 44]
  ------------------
 4777|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4778|      0|	}
 4779|       |
 4780|       |	/*
 4781|       |	 * alg_id=06 is a place holder for all RSA keys.
 4782|       |	 * Derive the real alg_id based on the size of the
 4783|       |	 * the data, as we are always using raw mode.
 4784|       |	 * Non RSA keys needs some work in this area.
 4785|       |	 */
 4786|       |
 4787|     44|	real_alg_id = priv->alg_id;
 4788|     44|	if (priv->alg_id == 0x06) {
  ------------------
  |  Branch (4788:6): [True: 15, False: 29]
  ------------------
 4789|     15|		switch (datalen) {
 4790|      0|		case 128:
  ------------------
  |  Branch (4790:3): [True: 0, False: 15]
  ------------------
 4791|      0|			real_alg_id = 0x06;
 4792|      0|			break;
 4793|     10|		case 256:
  ------------------
  |  Branch (4793:3): [True: 10, False: 5]
  ------------------
 4794|     10|			real_alg_id = 0x07;
 4795|     10|			break;
 4796|      0|		case 384:
  ------------------
  |  Branch (4796:3): [True: 0, False: 15]
  ------------------
 4797|      0|			real_alg_id = 0x05;
 4798|      0|			break;
 4799|      0|		case 512:
  ------------------
  |  Branch (4799:3): [True: 0, False: 15]
  ------------------
 4800|      0|			real_alg_id = 0x16;
 4801|      0|			break;
 4802|      5|		default:
  ------------------
  |  Branch (4802:3): [True: 5, False: 10]
  ------------------
 4803|      5|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 4804|     15|		}
 4805|     15|	}
 4806|       |	/* EC and ED alg_id was already set */
 4807|       |
 4808|     39|	piv_yk_notify_touch_policy(card, priv->key_ref);
 4809|     39|	r = piv_general_io(card, 0x87, real_alg_id, priv->key_ref,
 4810|     39|			sbuf, p - sbuf, rbuf, sizeof rbuf);
 4811|     39|	if (r < 0)
  ------------------
  |  Branch (4811:6): [True: 29, False: 10]
  ------------------
 4812|     29|		goto err;
 4813|       |
 4814|     10|	p2 = rbuf;
 4815|     10|	r = sc_asn1_read_tag(&p2, r, &cla, &tag, &bodylen);
 4816|     10|	if (p2 == NULL || r < 0 || bodylen == 0 || (cla | tag) != 0x7C) {
  ------------------
  |  Branch (4816:6): [True: 1, False: 9]
  |  Branch (4816:20): [True: 1, False: 8]
  |  Branch (4816:29): [True: 2, False: 6]
  |  Branch (4816:45): [True: 1, False: 5]
  ------------------
 4817|      5|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x7C");
  ------------------
  |  |  184|      5|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      5|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      5|	int _ret = (r); \
  |  |  |  |  178|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      5|		goto err; \
  |  |  |  |  182|      5|	} \
  |  |  |  |  183|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4818|      5|	}
 4819|       |
 4820|      5|	r = sc_asn1_read_tag(&p2, bodylen, &cla, &tag, &taglen);
 4821|      5|	if (p2 == NULL || r < 0 || taglen == 0 || (cla | tag) != 0x82) {
  ------------------
  |  Branch (4821:6): [True: 1, False: 4]
  |  Branch (4821:20): [True: 1, False: 3]
  |  Branch (4821:29): [True: 1, False: 2]
  |  Branch (4821:44): [True: 1, False: 1]
  ------------------
 4822|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4823|      4|	}
 4824|       |
 4825|      1|	if (taglen > outlen) {
  ------------------
  |  Branch (4825:6): [True: 0, False: 1]
  ------------------
 4826|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4827|      0|	}
 4828|       |
 4829|      1|	memcpy(out, p2, taglen);
 4830|      1|	r = (int)taglen;
 4831|       |
 4832|     39|err:
 4833|     39|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     39|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     39|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     39|	int _ret = r; \
  |  |  |  |  155|     39|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 38, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  157|     38|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     38|	} 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|     39|	return _ret; \
  |  |  |  |  163|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4834|     39|}
card-piv.c:piv_yk_notify_touch_policy:
 4723|     39|{
 4724|     39|	u8 touch_policy;
 4725|     39|	const char *title = "Touch your Yubikey to continue";
 4726|       |
 4727|     39|	piv_yk_get_metadata(card, key_ref, NULL, &touch_policy);
 4728|     39|	switch (touch_policy) {
  ------------------
  |  Branch (4728:10): [True: 2, False: 37]
  ------------------
 4729|      1|	case 0x02:
  ------------------
  |  Branch (4729:2): [True: 1, False: 38]
  ------------------
 4730|      1|		sc_notify(title, "Touching the token is required for unlocking the key");
 4731|      1|		break;
 4732|      1|	case 0x03:
  ------------------
  |  Branch (4732:2): [True: 1, False: 38]
  ------------------
 4733|      1|		sc_notify(title, "Touching the token is required unlocking the key (needed again after 15 seconds)");
 4734|      1|		break;
 4735|     39|	}
 4736|     39|}
card-piv.c:piv_yk_get_metadata:
 4504|    508|{
 4505|    508|	sc_apdu_t apdu;
 4506|    508|	u8 resp[100];
 4507|    508|	size_t i;
 4508|    508|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    508|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4509|       |
 4510|       |	/* initialize with the default behaviour */
 4511|    508|	if (pin_policy)
  ------------------
  |  Branch (4511:6): [True: 469, False: 39]
  ------------------
 4512|    469|		*pin_policy = 0x00;
 4513|    508|	if (touch_policy)
  ------------------
  |  Branch (4513:6): [True: 39, False: 469]
  ------------------
 4514|     39|		*touch_policy = 0x00;
 4515|       |
 4516|    508|	if (priv->yubico_version < 0x00050300) {
  ------------------
  |  Branch (4516:6): [True: 234, False: 274]
  ------------------
 4517|    234|		if (priv->yubico_version != 0)
  ------------------
  |  Branch (4517:7): [True: 54, False: 180]
  ------------------
 4518|     54|			sc_log(card->ctx, "Yubikey's PIN and touch policy not available");
  ------------------
  |  |   71|     54|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4519|    234|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    234|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4520|    234|	}
 4521|       |
 4522|    280|	for (i = 0; i < (sizeof(priv->yk_pin) / sizeof(*priv->yk_pin) - 1); i++) {
  ------------------
  |  Branch (4522:14): [True: 280, False: 0]
  ------------------
 4523|    280|		if (priv->yk_pin[i].slot == 0x00)
  ------------------
  |  Branch (4523:7): [True: 272, False: 8]
  ------------------
 4524|       |			/* reached the last initialized entry */
 4525|    272|			break;
 4526|       |
 4527|      8|		if (priv->yk_pin[i].slot == slot)
  ------------------
  |  Branch (4527:7): [True: 2, False: 6]
  ------------------
 4528|       |			/* metadata already initialized */
 4529|      2|			break;
 4530|      8|	}
 4531|       |
 4532|    274|	if (priv->yk_pin[i].slot == 0x00) {
  ------------------
  |  Branch (4532:6): [True: 272, False: 2]
  ------------------
 4533|       |		/* initialize this entry */
 4534|    272|		sc_format_apdu_ex(&apdu, 0x00, 0xF7, 0x00, slot, NULL, 0, resp, sizeof resp);
 4535|    272|		if (SC_SUCCESS == sc_transmit_apdu(card, &apdu) && SC_SUCCESS == sc_check_sw(card, apdu.sw1, apdu.sw2) && SC_SUCCESS == piv_yk_metadata_get_policy(card->ctx, resp, apdu.resplen, &priv->yk_pin[i].policy, &priv->yk_pin[i].touch)) {
  ------------------
  |  |   28|    272|#define SC_SUCCESS				0
  ------------------
              		if (SC_SUCCESS == sc_transmit_apdu(card, &apdu) && SC_SUCCESS == sc_check_sw(card, apdu.sw1, apdu.sw2) && SC_SUCCESS == piv_yk_metadata_get_policy(card->ctx, resp, apdu.resplen, &priv->yk_pin[i].policy, &priv->yk_pin[i].touch)) {
  ------------------
  |  |   28|    260|#define SC_SUCCESS				0
  ------------------
              		if (SC_SUCCESS == sc_transmit_apdu(card, &apdu) && SC_SUCCESS == sc_check_sw(card, apdu.sw1, apdu.sw2) && SC_SUCCESS == piv_yk_metadata_get_policy(card->ctx, resp, apdu.resplen, &priv->yk_pin[i].policy, &priv->yk_pin[i].touch)) {
  ------------------
  |  |   28|     41|#define SC_SUCCESS				0
  ------------------
  |  Branch (4535:7): [True: 260, False: 12]
  |  Branch (4535:54): [True: 41, False: 219]
  |  Branch (4535:109): [True: 10, False: 31]
  ------------------
 4536|     10|			sc_log(card->ctx, "PIN policy for slot 0x%02X: 0x%02X (touch 0x%02X)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4537|     10|					slot, priv->yk_pin[i].policy, priv->yk_pin[i].touch);
 4538|     10|			priv->yk_pin[i].slot = slot;
 4539|    262|		} else {
 4540|    262|			sc_log(card->ctx, "Could not get Yubikey's PIN and touch policy");
  ------------------
  |  |   71|    262|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4541|    262|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    262|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4542|    262|		}
 4543|    272|	} else if (priv->yk_pin[i].slot != slot) {
  ------------------
  |  Branch (4543:13): [True: 0, False: 2]
  ------------------
 4544|      0|		sc_log(card->ctx, "No free slot found");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4545|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4546|      0|	}
 4547|       |
 4548|     12|	if (pin_policy)
  ------------------
  |  Branch (4548:6): [True: 10, False: 2]
  ------------------
 4549|     10|		*pin_policy = priv->yk_pin[i].policy;
 4550|     12|	if (touch_policy)
  ------------------
  |  Branch (4550:6): [True: 2, False: 10]
  ------------------
 4551|      2|		*touch_policy = priv->yk_pin[i].touch;
 4552|       |
 4553|     12|	return SC_SUCCESS;
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
 4554|    274|}
card-piv.c:piv_yk_metadata_get_policy:
 4489|     41|{
 4490|     41|	size_t policylen;
 4491|     41|	const u8 *policy = sc_asn1_find_tag(ctx, buf, buflen, 0x02, &policylen);
 4492|     41|	if (policy && policylen == 2) {
  ------------------
  |  Branch (4492:6): [True: 21, False: 20]
  |  Branch (4492:16): [True: 10, False: 11]
  ------------------
 4493|     10|		*pin = policy[0];
 4494|     10|		*touch = policy[1];
 4495|     10|		return SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
 4496|     31|	} else {
 4497|     31|		sc_log(ctx, "Yubikey PIN policy not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4498|     31|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|     31|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4499|     31|	}
 4500|     41|}
card-piv.c:piv_decipher:
 4889|     13|{
 4890|     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]
  |  |  ------------------
  ------------------
 4891|       |
 4892|     13|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, piv_validate_general_authentication(card, data, datalen, out, outlen));
  ------------------
  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     13|	int _ret = r; \
  |  |  155|     13|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 12, False: 1]
  |  |  ------------------
  |  |  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|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 9, False: 3]
  |  |  ------------------
  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     12|	} 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|     13|	return _ret; \
  |  |  163|     13|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4893|     13|}
card-piv.c:piv_check_sw:
 6167|  13.4k|{
 6168|  13.4k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6169|       |
 6170|  13.4k|	int r;
 6171|       |#ifdef ENABLE_PIV_SM
 6172|       |	int i;
 6173|       |#endif
 6174|  13.4k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  13.4k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6175|       |
 6176|  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]
  |  |  ------------------
  ------------------
 6177|       |
 6178|       |	/* may be called before piv_init has allocated priv */
 6179|  13.4k|	if (priv) {
  ------------------
  |  Branch (6179:6): [True: 13.4k, False: 0]
  ------------------
 6180|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6181|       |
 6182|  13.4k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6182:7): [True: 61, False: 13.3k]
  ------------------
 6183|     61|			priv->pin_cmd_verify_sw1 = sw1;
 6184|     61|			priv->pin_cmd_verify_sw2 = sw2;
 6185|  13.3k|		} else {
 6186|       |			/* a command has completed and it is not verify
 6187|       |			 * If we are in a context_specific sequence, unlock
 6188|       |			 * This just decrements the extra lock count
 6189|       |			 */
 6190|  13.3k|			if (priv->context_specific) {
  ------------------
  |  Branch (6190:8): [True: 7, False: 13.3k]
  ------------------
 6191|      7|				sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC lock");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6192|      7|				priv->context_specific = 0;
 6193|      7|				sc_unlock(card);
 6194|      7|			}
 6195|  13.3k|		}
 6196|       |
 6197|  13.4k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  584|  13.4k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6197:7): [True: 780, False: 12.6k]
  ------------------
 6198|       |
 6199|       |			/* Handle the Yubikey NEO or any other PIV card which returns in response to a verify
 6200|       |			 * 63 0X rather than 63 CX indicate the number of remaining PIN retries.
 6201|       |			 * Perhaps they misread the spec and thought 0xCX meant "clear" or "don't care", not a literal 0xC!
 6202|       |			 */
 6203|    780|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6203:8): [True: 31, False: 749]
  |  Branch (6203:32): [True: 2, False: 29]
  ------------------
 6204|      2|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6205|      2|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6205:9): [True: 1, False: 1]
  ------------------
 6206|      1|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6207|      1|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      1|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6208|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6209|      1|				}
 6210|      2|			}
 6211|    780|		}
 6212|  13.4k|	}
 6213|       |#ifdef ENABLE_PIV_SM
 6214|       |	/* Note 6982 is map to SC_ERROR_SM_NO_SESSION_KEYS but iso maps it to SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
 6215|       |	/* we do this because 6982 could also mean a verify is not allowed over contactless without VCI */
 6216|       |	/* we stashed the sw1 and sw2 above for verify */
 6217|       |	/* Check specific NIST sp800-73-4 SM  errors */
 6218|       |	for (i = 0; piv_sm_errors[i].SWs != 0; i++) {
 6219|       |		if (piv_sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
 6220|       |			sc_log(card->ctx, "%s", piv_sm_errors[i].errorstr);
 6221|       |			return piv_sm_errors[i].errorno;
 6222|       |		}
 6223|       |	}
 6224|       |#endif
 6225|  13.4k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6226|  13.4k|	return r;
 6227|  13.4k|}
card-piv.c:piv_card_ctl:
 4565|  46.2k|{
 4566|  46.2k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  46.2k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4567|  46.2k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4568|       |
 4569|  46.2k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  46.2k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  46.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  46.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  46.2k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 46.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4570|       |
 4571|  46.2k|	if (priv == NULL) {
  ------------------
  |  Branch (4571:6): [True: 0, False: 46.2k]
  ------------------
 4572|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4573|      0|	}
 4574|  46.2k|	switch (cmd) {
  ------------------
  |  Branch (4574:10): [True: 46.2k, False: 0]
  ------------------
 4575|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4575:2): [True: 0, False: 46.2k]
  ------------------
 4576|      0|		opts = (u8 *)ptr;
 4577|      0|		switch (*opts) {
  ------------------
  |  Branch (4577:11): [True: 0, False: 0]
  ------------------
 4578|      0|		case 'A':
  ------------------
  |  Branch (4578:3): [True: 0, False: 0]
  ------------------
 4579|      0|			return piv_general_external_authenticate(card,
 4580|      0|					*(opts + 1), *(opts + 2));
 4581|      0|			break;
 4582|      0|		case 'M':
  ------------------
  |  Branch (4582:3): [True: 0, False: 0]
  ------------------
 4583|      0|			return piv_general_mutual_authenticate(card,
 4584|      0|					*(opts + 1), *(opts + 2));
 4585|      0|			break;
 4586|      0|		}
 4587|      0|		break;
 4588|      0|	case SC_CARDCTL_PIV_GENERATE_KEY:
  ------------------
  |  Branch (4588:2): [True: 0, False: 46.2k]
  ------------------
 4589|      0|		return piv_generate_key(card,
 4590|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4591|      0|		break;
 4592|    716|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4592:2): [True: 716, False: 45.5k]
  ------------------
 4593|    716|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4594|      0|		break;
 4595|    716|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4595:2): [True: 716, False: 45.5k]
  ------------------
 4596|    716|		return piv_get_pin_preference(card, ptr);
 4597|      0|		break;
 4598|  44.3k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4598:2): [True: 44.3k, False: 1.90k]
  ------------------
 4599|  44.3k|		return piv_is_object_present(card, ptr);
 4600|      0|		break;
 4601|    469|	case SC_CARDCTL_PIV_YK_PIN_POLICY:
  ------------------
  |  Branch (4601:2): [True: 469, False: 45.8k]
  ------------------
 4602|    469|		return piv_yk_pin_policy(card, ptr);
 4603|      0|		break;
 4604|  46.2k|	}
 4605|       |
 4606|      0|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4607|      0|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4369|    716|{
 4370|    716|	int r;
 4371|    716|	int i;
 4372|    716|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4373|    716|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4374|    716|	u8 *rbuf = NULL;
 4375|    716|	const u8 *body;
 4376|    716|	const u8 *fascn;
 4377|    716|	const u8 *guid;
 4378|    716|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4379|       |
 4380|    716|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    716|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    716|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    716|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 716]
  |  |  ------------------
  ------------------
 4381|    716|	if (card->serialnr.len) {
  ------------------
  |  Branch (4381:6): [True: 0, False: 716]
  ------------------
 4382|      0|		*serial = card->serialnr;
 4383|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4384|      0|	}
 4385|       |
 4386|       |	/*
 4387|       |	 * 800-73-3 Part 1 and CIO Council docs say for PIV Compatible cards
 4388|       |	 * the FASC-N Agency code should be 9999 and there should be a GUID
 4389|       |	 * based on RFC 4122. If GUID present and not zero
 4390|       |	 * we will use the GUID as the serial number.
 4391|       |	 */
 4392|       |
 4393|    716|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4394|    716|	LOG_TEST_RET(card->ctx, r, "Failure retrieving CHUI");
  ------------------
  |  |  174|    716|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    716|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    716|	int _ret = (r); \
  |  |  |  |  168|    716|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 651, False: 65]
  |  |  |  |  ------------------
  |  |  |  |  169|    651|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    651|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    651|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    651|		return _ret; \
  |  |  |  |  172|    651|	} \
  |  |  |  |  173|    716|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 65]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4395|       |
 4396|     65|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     65|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4397|     65|	if (rbuflen != 0) {
  ------------------
  |  Branch (4397:6): [True: 65, False: 0]
  ------------------
 4398|     65|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4399|     65|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4399:7): [True: 65, False: 0]
  |  Branch (4399:23): [True: 63, False: 2]
  |  Branch (4399:39): [True: 63, False: 0]
  ------------------
 4400|     63|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4401|       |
 4402|     63|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4402:8): [True: 38, False: 25]
  |  Branch (4402:17): [True: 33, False: 5]
  ------------------
 4403|    858|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4403:17): [True: 825, False: 33]
  ------------------
 4404|    825|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4404:14): [True: 654, False: 171]
  |  Branch (4404:23): [True: 32, False: 139]
  ------------------
 4405|    825|				}
 4406|     33|			}
 4407|       |
 4408|     63|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4409|       |
 4410|     63|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4410:8): [True: 19, False: 44]
  |  Branch (4410:16): [True: 17, False: 2]
  ------------------
 4411|    289|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4411:17): [True: 272, False: 17]
  ------------------
 4412|    272|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4413|    272|				}
 4414|     17|			}
 4415|     63|			sc_log(card->ctx, "fascn=%p,fascnlen=%zu,guid=%p,guidlen=%zu,gbits=%2.2x",
  ------------------
  |  |   71|     63|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4416|     63|					fascn, fascnlen, guid, guidlen, gbits);
 4417|       |
 4418|     63|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4418:8): [True: 38, False: 25]
  |  Branch (4418:17): [True: 33, False: 5]
  |  Branch (4418:35): [True: 32, False: 1]
  ------------------
 4419|       |				/* test if guid and the fascn starts with ;9999 (in ISO 4bit + parity code) */
 4420|       |				/* ;9999 is non-gov issued FASC-N, will use FASC-N for gov issued if no guid */
 4421|     32|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4421:11): [True: 16, False: 16]
  |  Branch (4421:20): [True: 15, False: 1]
  |  Branch (4421:40): [True: 12, False: 3]
  ------------------
 4422|     31|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4422:11): [True: 2, False: 10]
  |  Branch (4422:31): [True: 1, False: 1]
  ------------------
 4423|       |					/* fascnlen is 25 */
 4424|     31|					serial->len = fascnlen;
 4425|     31|					memcpy(serial->value, fascn, serial->len);
 4426|     31|					r = SC_SUCCESS;
  ------------------
  |  |   28|     31|#define SC_SUCCESS				0
  ------------------
 4427|     31|					gbits = 0; /* set to skip using guid below */
 4428|     31|				}
 4429|     32|			}
 4430|     63|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4430:8): [True: 19, False: 44]
  |  Branch (4430:16): [True: 17, False: 2]
  |  Branch (4430:33): [True: 2, False: 15]
  ------------------
 4431|      2|				serial->len = guidlen;
 4432|      2|				memcpy(serial->value, guid, serial->len);
 4433|      2|				r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 4434|      2|			}
 4435|     63|		}
 4436|     65|	}
 4437|       |
 4438|     65|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4438:6): [True: 33, False: 32]
  |  Branch (4438:20): [True: 32, False: 1]
  ------------------
 4439|     32|		serial->len = 16;
 4440|     32|		memset(serial->value, 0x00, serial->len);
 4441|     32|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     32|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4442|     32|	}
 4443|       |
 4444|     65|	card->serialnr = *serial;
 4445|     65|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     65|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     65|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     65|	int _ret = r; \
  |  |  |  |  155|     65|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 65, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     65|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32, False: 33]
  |  |  |  |  ------------------
  |  |  |  |  157|     65|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     65|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     65|	return _ret; \
  |  |  |  |  163|     65|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4446|     65|}
card-piv.c:piv_get_pin_preference:
 4480|    716|{
 4481|    716|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|    716|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4482|       |
 4483|    716|	*pin_ref = priv->pin_preference;
 4484|    716|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    716|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    716|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    716|	int _ret = r; \
  |  |  |  |  155|    716|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 716, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    716|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 716]
  |  |  |  |  ------------------
  |  |  |  |  157|    716|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    716|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    716|	return _ret; \
  |  |  |  |  163|    716|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4485|    716|}
card-piv.c:piv_is_object_present:
 4461|  44.3k|{
 4462|  44.3k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|  44.3k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4463|  44.3k|	int r = 0;
 4464|  44.3k|	int enumtag;
 4465|       |
 4466|  44.3k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4467|  44.3k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  153|  43.6k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4467:6): [True: 43.6k, False: 716]
  |  Branch (4467:22): [True: 28.4k, False: 15.2k]
  ------------------
 4468|  28.4k|		r = 1;
 4469|       |
 4470|  44.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  44.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  44.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  44.3k|	int _ret = r; \
  |  |  |  |  155|  44.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15.9k, False: 28.4k]
  |  |  |  |  ------------------
  |  |  |  |  156|  15.9k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 15.9k]
  |  |  |  |  ------------------
  |  |  |  |  157|  15.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  28.4k|	} else { \
  |  |  |  |  159|  28.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  28.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  28.4k|	} \
  |  |  |  |  162|  44.3k|	return _ret; \
  |  |  |  |  163|  44.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4471|  44.3k|}
card-piv.c:piv_yk_pin_policy:
 4558|    469|{
 4559|    469|	u8 slot = *ptr;
 4560|    469|	LOG_FUNC_RETURN(card->ctx, piv_yk_get_metadata(card, slot, ptr, NULL));
  ------------------
  |  |  164|    469|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    469|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    469|	int _ret = r; \
  |  |  |  |  155|    469|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 469, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    469|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    459|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 459, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  157|    469|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    469|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    469|	return _ret; \
  |  |  |  |  163|    469|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4561|    469|}
card-piv.c:piv_pin_cmd:
 6300|     47|{
 6301|     47|	int r = 0;
 6302|     47|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  440|     47|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6303|       |
 6304|       |	/* Extra validation of (new) PIN during a PIN change request, to
 6305|       |	 * ensure it's not outside the FIPS 201 4.1.6.1 (numeric only) and
 6306|       |	 * FIPS 140-2 (6 character minimum) requirements.
 6307|       |	 */
 6308|     47|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6309|       |
 6310|     47|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     47|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     47|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     47|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 47]
  |  |  ------------------
  ------------------
 6311|     47|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|     47|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6312|     47|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|     47|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (6312:6): [True: 0, False: 47]
  ------------------
 6313|      0|		size_t i = 0;
 6314|      0|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (6314:7): [True: 0, False: 0]
  ------------------
 6315|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 6316|      0|		}
 6317|      0|		for (i = 0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (6317:15): [True: 0, False: 0]
  ------------------
 6318|      0|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (6318:8): [True: 0, False: 0]
  ------------------
 6319|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 6320|      0|			}
 6321|      0|		}
 6322|      0|	}
 6323|       |
 6324|     47|	priv->pin_cmd_verify_sw1 = 0x00U;
 6325|       |
 6326|     47|	if (data->cmd == SC_PIN_CMD_GET_INFO) { /* fill in what we think it should be */
  ------------------
  |  |  418|     47|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6326:6): [True: 0, False: 47]
  ------------------
 6327|      0|		data->pin1.logged_in = priv->logged_in;
 6328|      0|		data->pin1.tries_left = priv->tries_left;
 6329|       |
 6330|       |		/*
 6331|       |		 * If called to check on the login state for a context specific login
 6332|       |		 * return not logged in. Needed because of logic in e6f7373ef066
 6333|       |		 */
 6334|      0|		if (data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|      0|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6334:7): [True: 0, False: 0]
  ------------------
 6335|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6336|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6337|      0|		}
 6338|       |
 6339|      0|		if (priv->logged_in & SC_PIN_STATE_LOGGED_IN) {
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  |  Branch (6339:7): [True: 0, False: 0]
  ------------------
 6340|       |			/* Avoid status requests when the user is logged in to handle NIST
 6341|       |			 * 800-73-4 Part 2:
 6342|       |			 * The PKI cryptographic function (see Table 4b) is protected with
 6343|       |			 * a “PIN Always” or “OCC Always” access rule. In other words, the
 6344|       |			 * PIN or OCC data must be submitted and verified every time
 6345|       |			 * immediately before a digital signature key operation.  This
 6346|       |			 * ensures cardholder participation every time the private key is
 6347|       |			 * used for digital signature generation */
 6348|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6349|      0|		}
 6350|      0|	}
 6351|       |
 6352|       |	/*
 6353|       |	 * If this was for a CKU_CONTEXT_SPECFIC login, lock the card one more time.
 6354|       |	 * to avoid any interference from other applications.
 6355|       |	 * Sc_unlock will be called at a later time after the next card command
 6356|       |	 * that should be a crypto operation. If its not then it is a error by the
 6357|       |	 * calling application.
 6358|       |	 */
 6359|     47|	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  415|     94|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|     47|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6359:6): [True: 47, False: 0]
  |  Branch (6359:40): [True: 20, False: 27]
  ------------------
 6360|     20|		priv->context_specific = 1;
 6361|     20|		sc_log(card->ctx, "Starting CONTEXT_SPECIFIC verify");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6362|     20|		r = sc_lock(card);
 6363|     20|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     20|#define SC_SUCCESS				0
  ------------------
  |  Branch (6363:7): [True: 0, False: 20]
  ------------------
 6364|      0|			sc_log(card->ctx, "sc_lock failed");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6365|      0|			return r;
 6366|      0|		}
 6367|     20|	}
 6368|       |
 6369|     47|	priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6370|     47|	r = iso_drv->ops->pin_cmd(card, data);
 6371|     47|	priv->pin_cmd_verify = 0;
 6372|       |
 6373|       |	/* tell user verify not supported on contactless without VCI */
 6374|     47|	if (priv->pin_cmd_verify_sw1 == 0x69 && priv->pin_cmd_verify_sw2 == 0x82 &&
  ------------------
  |  Branch (6374:6): [True: 3, False: 44]
  |  Branch (6374:42): [True: 1, False: 2]
  ------------------
 6375|      1|			priv->init_flags & PIV_INIT_CONTACTLESS &&
  ------------------
  |  |  385|     48|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (6375:4): [True: 0, False: 1]
  ------------------
 6376|      0|			card->type == SC_CARD_TYPE_PIV_II_800_73_4) {
  ------------------
  |  Branch (6376:4): [True: 0, False: 0]
  ------------------
 6377|      0|		sc_log(card->ctx, "Token does not support pin verify over contacless reader");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6378|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 6379|      0|	}
 6380|       |
 6381|       |	/* if verify failed, release the lock */
 6382|     47|	if (data->cmd == SC_PIN_CMD_VERIFY && r < 0 && priv->context_specific) {
  ------------------
  |  |  415|     94|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6382:6): [True: 47, False: 0]
  |  Branch (6382:40): [True: 27, False: 20]
  |  Branch (6382:49): [True: 9, False: 18]
  ------------------
 6383|      9|		sc_log(card->ctx, "Clearing CONTEXT_SPECIFIC");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6384|      9|		priv->context_specific = 0;
 6385|      9|		sc_unlock(card);
 6386|      9|	}
 6387|       |
 6388|       |	/* if access to applet is know to be reset by other driver  we select_aid and try again */
 6389|     47|	if (priv->card_issues & CI_OTHER_AID_LOSE_STATE && priv->pin_cmd_verify_sw1 == 0x6DU) {
  ------------------
  |  |  593|     94|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
  |  Branch (6389:6): [True: 32, False: 15]
  |  Branch (6389:53): [True: 14, False: 18]
  ------------------
 6390|     14|		sc_log(card->ctx, "AID may be lost doing piv_find_aid and retry pin_cmd");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6391|     14|		piv_find_aid(card);
 6392|       |
 6393|     14|		priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6394|     14|		r = iso_drv->ops->pin_cmd(card, data);
 6395|     14|		priv->pin_cmd_verify = 0;
 6396|     14|	}
 6397|       |
 6398|       |	/* If verify worked, we are logged_in */
 6399|     47|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  415|     47|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6399:6): [True: 47, False: 0]
  ------------------
 6400|     47|		if (r >= 0)
  ------------------
  |  Branch (6400:7): [True: 25, False: 22]
  ------------------
 6401|     25|			priv->logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|     25|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6402|     22|		else
 6403|     22|			priv->logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     22|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6404|     47|	}
 6405|       |
 6406|       |	/* Some cards never return 90 00  for SC_PIN_CMD_GET_INFO even if the card state is verified */
 6407|       |	/* PR 797 has changed the return codes from pin_cmd, and added a data->pin1.logged_in flag */
 6408|       |
 6409|     47|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|     47|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6409:6): [True: 0, False: 47]
  ------------------
 6410|      0|		if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) {
  ------------------
  |  |  588|      0|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6410:7): [True: 0, False: 0]
  ------------------
 6411|      0|			sc_log(card->ctx, "CI_CANT_USE_GETDATA_FOR_STATE set, assume logged_in=%d", priv->logged_in);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6412|      0|			data->pin1.logged_in = priv->logged_in; /* use what ever we saw last */
 6413|      0|		} else if (priv->card_issues & CI_VERIFY_LC0_FAIL &&
  ------------------
  |  |  585|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
  |  Branch (6413:14): [True: 0, False: 0]
  ------------------
 6414|      0|				priv->pin_cmd_verify_sw1 == 0x63U) { /* can not use modified return codes from iso->drv->pin_cmd */
  ------------------
  |  Branch (6414:5): [True: 0, False: 0]
  ------------------
 6415|       |			/* try another method, looking at a protected object this may require adding one of these to NEO */
 6416|      0|			r = piv_check_protected_objects(card);
 6417|      0|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (6417:8): [True: 0, False: 0]
  ------------------
 6418|      0|				data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6419|      0|			else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (6419:13): [True: 0, False: 0]
  ------------------
 6420|      0|				if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) { /* we still can not determine login state */
  ------------------
  |  |  588|      0|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6420:9): [True: 0, False: 0]
  ------------------
 6421|       |
 6422|      0|					data->pin1.logged_in = priv->logged_in; /* may have be set from SC_PIN_CMD_VERIFY */
 6423|      0|				} else {
 6424|      0|					data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6425|      0|				}
 6426|      0|				r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 6427|      0|			}
 6428|      0|		}
 6429|      0|		priv->logged_in = data->pin1.logged_in;
 6430|      0|		priv->tries_left = data->pin1.tries_left;
 6431|      0|	}
 6432|       |
 6433|     47|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|     47|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6434|     47|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     47|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     47|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     47|	int _ret = r; \
  |  |  |  |  155|     47|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 47, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     47|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     22|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 22, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  157|     47|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     47|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     47|	return _ret; \
  |  |  |  |  163|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6435|     47|}
card-piv.c:piv_card_reader_lock_obtained:
 6474|  6.53k|{
 6475|  6.53k|	int r = 0;
 6476|  6.53k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6477|  6.53k|	size_t templen = sizeof(temp);
 6478|  6.53k|	piv_private_data_t *priv = PIV_DATA(card); /* may be null */
  ------------------
  |  |  440|  6.53k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6479|       |
 6480|  6.53k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.53k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.53k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.53k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.53k]
  |  |  ------------------
  ------------------
 6481|       |
 6482|       |	/* We have a PCSC transaction and sc_lock */
 6483|  6.53k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6483:6): [True: 5.02k, False: 1.51k]
  |  Branch (6483:22): [True: 724, False: 790]
  ------------------
 6484|  5.74k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  11.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:103): [True: 724, False: 5.02k]
  |  |  ------------------
  ------------------
 6485|  5.74k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6486|  5.74k|		r = 0; /* do nothing, piv_match will take care of it */
 6487|  5.74k|		goto err;
 6488|  5.74k|	}
 6489|       |
 6490|    790|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|    790|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6491|       |
 6492|       |	/* make sure our application is active */
 6493|       |
 6494|       |	/* first see if AID is active AID by reading discovery object '7E' */
 6495|       |	/* If not try selecting AID */
 6496|       |
 6497|       |	/* but if card does not support DISCOVERY object we can not use it */
 6498|    790|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  590|    790|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6498:6): [True: 740, False: 50]
  ------------------
 6499|    740|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|    740|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6500|    740|	} else {
 6501|     50|		r = piv_find_discovery(card);
 6502|       |#ifdef ENABLE_PIV_SM
 6503|       |		/*
 6504|       |		 * All 800-73-4 cards that support SM, also have a discovery object with
 6505|       |		 * the pin_policy, so can not have CI_DISCOVERY_USELESS
 6506|       |		 * Discovery object can be read with contact or contactless
 6507|       |		 * If read with SM and fails with 69 88  SC_ERROR_SM_INVALID_SESSION_KEY
 6508|       |		 * sm.c will close the SM connectrion, and set defer
 6509|       |		 */
 6510|       |		if (was_reset == 0 && (r == SC_ERROR_SM_INVALID_SESSION_KEY || priv->sm_flags & PIV_SM_FLAGS_DEFER_OPEN)) {
 6511|       |			sc_log(card->ctx, "SC_ERROR_SM_INVALID_SESSION_KEY || PIV_SM_FLAGS_DEFER_OPEN");
 6512|       |			piv_sm_open(card);
 6513|       |			r = piv_find_discovery(card);
 6514|       |		}
 6515|       |#endif /* ENABLE_PIV_SM */
 6516|     50|	}
 6517|       |
 6518|    790|	if (r < 0) {
  ------------------
  |  Branch (6518:6): [True: 781, False: 9]
  ------------------
 6519|    781|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  591|    781|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6519:7): [True: 0, False: 781]
  |  Branch (6519:24): [True: 771, False: 10]
  ------------------
 6520|    771|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6521|    771|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|    771|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6522|    771|		} else {
 6523|     10|			r = 0; /* can't do anything with this card, hope there was no interference */
 6524|     10|		}
 6525|    781|	}
 6526|       |
 6527|    790|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6527:6): [True: 618, False: 172]
  ------------------
 6528|    618|		goto err;
 6529|       |
 6530|    172|	if (was_reset > 0)
  ------------------
  |  Branch (6530:6): [True: 0, False: 172]
  ------------------
 6531|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6532|       |
 6533|    172|	r = 0;
 6534|       |
 6535|  6.53k|err:
 6536|  6.53k|	if (priv)
  ------------------
  |  Branch (6536:6): [True: 1.51k, False: 5.02k]
  ------------------
 6537|  1.51k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  1.51k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6538|  6.53k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  6.53k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.53k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.53k|	int _ret = r; \
  |  |  |  |  155|  6.53k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.53k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.53k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    618|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 618, False: 5.91k]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.53k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.53k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  6.53k|	return _ret; \
  |  |  |  |  163|  6.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6539|  6.53k|}

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

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

sc_get_sc_hsm_driver:
 2003|  14.1k|{
 2004|  14.1k|	return sc_get_driver();
 2005|  14.1k|}
card-sc-hsm.c:sc_get_driver:
 1967|  14.1k|{
 1968|  14.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1969|       |
 1970|  14.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1970:6): [True: 1, False: 14.1k]
  ------------------
 1971|      1|		iso_ops = iso_drv->ops;
 1972|       |
 1973|  14.1k|	sc_hsm_ops                   = *iso_drv->ops;
 1974|  14.1k|	sc_hsm_ops.match_card        = sc_hsm_match_card;
 1975|  14.1k|	sc_hsm_ops.select_file       = sc_hsm_select_file;
 1976|  14.1k|	sc_hsm_ops.get_challenge     = sc_hsm_get_challenge;
 1977|  14.1k|	sc_hsm_ops.read_binary       = sc_hsm_read_binary;
 1978|  14.1k|	sc_hsm_ops.update_binary     = sc_hsm_update_binary;
 1979|  14.1k|	sc_hsm_ops.list_files        = sc_hsm_list_files;
 1980|  14.1k|	sc_hsm_ops.create_file       = sc_hsm_create_file;
 1981|  14.1k|	sc_hsm_ops.delete_file       = sc_hsm_delete_file;
 1982|  14.1k|	sc_hsm_ops.set_security_env  = sc_hsm_set_security_env;
 1983|  14.1k|	sc_hsm_ops.compute_signature = sc_hsm_compute_signature;
 1984|  14.1k|	sc_hsm_ops.decipher          = sc_hsm_decipher;
 1985|  14.1k|	sc_hsm_ops.init              = sc_hsm_init;
 1986|  14.1k|	sc_hsm_ops.finish            = sc_hsm_finish;
 1987|  14.1k|	sc_hsm_ops.card_ctl          = sc_hsm_card_ctl;
 1988|  14.1k|	sc_hsm_ops.pin_cmd           = sc_hsm_pin_cmd;
 1989|  14.1k|	sc_hsm_ops.logout            = sc_hsm_logout;
 1990|       |
 1991|       |	/* no record oriented file services */
 1992|  14.1k|	sc_hsm_ops.read_record       = NULL;
 1993|  14.1k|	sc_hsm_ops.write_record      = NULL;
 1994|  14.1k|	sc_hsm_ops.append_record     = NULL;
 1995|  14.1k|	sc_hsm_ops.update_record     = NULL;
 1996|       |
 1997|  14.1k|	return &sc_hsm_drv;
 1998|  14.1k|}
card-sc-hsm.c:sc_hsm_match_card:
  267|  5.42k|{
  268|  5.42k|	sc_path_t path;
  269|  5.42k|	int i, r, type = 0;
  270|  5.42k|	sc_file_t *file = NULL;
  271|       |
  272|  5.42k|	i = _sc_match_atr(card, sc_hsm_atrs, &type);
  273|  5.42k|	if (i >= 0 && type != SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (273:6): [True: 117, False: 5.30k]
  |  Branch (273:16): [True: 116, False: 1]
  ------------------
  274|    116|		card->type = type;
  275|    116|		return 1;
  276|    116|	}
  277|       |
  278|  5.30k|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|  5.30k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  279|  5.30k|	r = sc_hsm_select_file(card, &path, &file);
  280|  5.30k|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  5.30k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.30k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.30k|	int _ret = (r); \
  |  |  |  |  168|  5.30k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.04k, False: 260]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.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|  5.04k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.04k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.04k|		return _ret; \
  |  |  |  |  172|  5.04k|	} \
  |  |  |  |  173|  5.30k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 260]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  281|       |
  282|       |	// Validate that card returns a FCP with a proprietary tag 85 with value longer than 2 byte (Fixes #1377)
  283|    260|	if (file != NULL) {
  ------------------
  |  Branch (283:6): [True: 260, False: 0]
  ------------------
  284|    260|		size_t sz = file->prop_attr_len;
  285|    260|		sc_file_free(file);
  286|    260|		if (sz < 2) {
  ------------------
  |  Branch (286:7): [True: 258, False: 2]
  ------------------
  287|    258|			return 0;
  288|    258|		}
  289|    260|	}
  290|       |
  291|      2|	if (type == SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (291:6): [True: 0, False: 2]
  ------------------
  292|      0|		card->type = SC_CARD_TYPE_SC_HSM_SOC;
  293|      2|	} else {
  294|      2|		card->type = SC_CARD_TYPE_SC_HSM;
  295|      2|	}
  296|       |
  297|      2|	return 1;
  298|    260|}
card-sc-hsm.c:sc_hsm_select_file:
  247|  5.90k|{
  248|  5.90k|	return sc_hsm_select_file_ex(card, in_path, 0, file_out);
  249|  5.90k|}
card-sc-hsm.c:sc_hsm_select_file_ex:
  149|  6.30k|{
  150|  6.30k|	int rv;
  151|  6.30k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  152|  6.30k|	sc_file_t *file = NULL;
  153|  6.30k|	sc_path_t cpath;
  154|  6.30k|	size_t card_max_recv_size = card->max_recv_size;
  155|  6.30k|	size_t reader_max_recv_size = card->reader->max_recv_size;
  156|       |
  157|  6.30k|	if (file_out == NULL) {				// Versions before 0.16 of the SmartCard-HSM do not support P2='0C'
  ------------------
  |  Branch (157:6): [True: 277, False: 6.02k]
  ------------------
  158|    277|		rv = sc_hsm_select_file_ex(card, in_path, forceselect, &file);
  159|    277|		sc_file_free(file);
  160|    277|		return rv;
  161|    277|	}
  162|       |
  163|  6.02k|	if ((in_path->type == SC_PATH_TYPE_FILE_ID) && in_path->aid.len) {
  ------------------
  |  |  117|  6.02k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (163:6): [True: 68, False: 5.95k]
  |  Branch (163:49): [True: 0, False: 68]
  ------------------
  164|       |		// Split applet selection and file selection into two separate calls
  165|      0|		cpath = *in_path;
  166|      0|		cpath.len = 0;
  167|      0|		cpath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  168|      0|		rv = sc_hsm_select_file_ex(card, &cpath, forceselect, NULL);
  169|      0|		LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|       |
  171|      0|		if (in_path->len) {
  ------------------
  |  Branch (171:7): [True: 0, False: 0]
  ------------------
  172|      0|			cpath = *in_path;
  173|      0|			cpath.aid.len = 0;
  174|      0|			rv = sc_hsm_select_file_ex(card, &cpath, forceselect, file_out);
  175|      0|		}
  176|      0|		return rv;
  177|      0|	}
  178|       |
  179|       |	// Prevent selection of applet unless this is the first time, selection is forced or the device is not authenticated
  180|  6.02k|	if (in_path->type == SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  12.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (180:6): [True: 5.66k, False: 360]
  ------------------
  181|    360|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    720|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (181:8): [True: 292, False: 68]
  ------------------
  182|    292|				&& in_path->len == sc_hsm_aid.len
  ------------------
  |  Branch (182:8): [True: 0, False: 292]
  ------------------
  183|      0|				&& !memcmp(in_path->value, sc_hsm_aid.value, sc_hsm_aid.len))
  ------------------
  |  Branch (183:8): [True: 0, False: 0]
  ------------------
  184|    360|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    720|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (184:8): [True: 292, False: 68]
  ------------------
  185|    292|				&& in_path->len == 0
  ------------------
  |  Branch (185:8): [True: 0, False: 292]
  ------------------
  186|      0|				&& in_path->aid.len == sc_hsm_aid.len
  ------------------
  |  Branch (186:8): [True: 0, False: 0]
  ------------------
  187|  5.66k|				&& !memcmp(in_path->aid.value, sc_hsm_aid.value, sc_hsm_aid.len))) {
  ------------------
  |  Branch (187:8): [True: 0, False: 0]
  ------------------
  188|  5.66k|		if (!priv || (priv->dffcp == NULL) || forceselect) {
  ------------------
  |  Branch (188:7): [True: 5.30k, False: 356]
  |  Branch (188:16): [True: 265, False: 91]
  |  Branch (188:41): [True: 0, False: 91]
  ------------------
  189|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  190|  5.57k|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|  5.57k|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  191|  5.57k|			rv = (*iso_ops->select_file)(card, in_path, file_out);
  192|  5.57k|			card->max_recv_size = card_max_recv_size;
  193|  5.57k|			card->reader->max_recv_size = reader_max_recv_size;
  194|  5.57k|			LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  5.57k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.57k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.57k|	int _ret = (r); \
  |  |  |  |  168|  5.57k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.23k, False: 340]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.23k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.23k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.23k|		return _ret; \
  |  |  |  |  172|  5.23k|	} \
  |  |  |  |  173|  5.57k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 340]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|       |
  196|    340|			if (priv) {
  ------------------
  |  Branch (196:8): [True: 80, False: 260]
  ------------------
  197|     80|				sc_file_free(priv->dffcp);
  198|       |				// Cache the FCP returned when selecting the applet
  199|     80|				sc_file_dup(&priv->dffcp, *file_out);
  200|     80|			}
  201|    340|		} else {
  202|     91|			sc_file_dup(file_out, priv->dffcp);
  203|     91|			rv = SC_SUCCESS;
  ------------------
  |  |   28|     91|#define SC_SUCCESS				0
  ------------------
  204|     91|		}
  205|    431|		return rv;
  206|  5.66k|	}
  207|       |
  208|    360|	if ((in_path->len >= 2) && (in_path->value[0] == 0x3F) && (in_path->value[1] == 0x00)) {
  ------------------
  |  Branch (208:6): [True: 360, False: 0]
  |  Branch (208:29): [True: 247, False: 113]
  |  Branch (208:60): [True: 244, False: 3]
  ------------------
  209|       |		// The SmartCard-HSM is an applet that is not default selected. Simulate selection of the MF
  210|    244|		if (in_path->len == 2) {
  ------------------
  |  Branch (210:7): [True: 0, False: 244]
  ------------------
  211|      0|			file = sc_file_new();
  212|      0|			if (file == NULL)
  ------------------
  |  Branch (212:8): [True: 0, False: 0]
  ------------------
  213|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  214|      0|			file->path = *in_path;
  215|      0|			file->id = 0x3F00;
  216|      0|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  217|      0|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  218|       |
  219|      0|			*file_out = file;
  220|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  221|    244|		} else {
  222|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  223|    244|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    244|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  224|    244|			sc_path_t truncated;
  225|    244|			memcpy(&truncated, in_path, sizeof truncated);
  226|    244|			truncated.len = in_path->len - 2;
  227|    244|			memcpy(truncated.value, in_path->value+2, truncated.len);
  228|    244|			rv = (*iso_ops->select_file)(card, &truncated, file_out);
  229|    244|			card->max_recv_size = card_max_recv_size;
  230|    244|			card->reader->max_recv_size = reader_max_recv_size;
  231|    244|			return rv;
  232|    244|		}
  233|    244|	}
  234|       |	/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  235|    116|	card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    116|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  236|    116|	rv = (*iso_ops->select_file)(card, in_path, file_out);
  237|    116|	card->max_recv_size = card_max_recv_size;
  238|    116|	card->reader->max_recv_size = reader_max_recv_size;
  239|    116|	return rv;
  240|    360|}
card-sc-hsm.c:sc_hsm_read_binary:
  799|    572|{
  800|    572|	sc_context_t *ctx = card->ctx;
  801|    572|	sc_apdu_t apdu;
  802|    572|	u8 cmdbuff[4];
  803|    572|	int r;
  804|       |
  805|    572|	if (idx > 0xffff) {
  ------------------
  |  Branch (805:6): [True: 0, False: 572]
  ------------------
  806|      0|		sc_log(ctx,  "invalid EF offset: 0x%X > 0xFFFF", idx);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  807|      0|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  808|      0|	}
  809|       |
  810|    572|	cmdbuff[0] = 0x54;
  811|    572|	cmdbuff[1] = 0x02;
  812|    572|	cmdbuff[2] = (idx >> 8) & 0xFF;
  813|    572|	cmdbuff[3] = idx & 0xFF;
  814|       |
  815|    572|	if (count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (815:6): [True: 0, False: 572]
  ------------------
  816|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  817|    572|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB1, 0x00, 0x00);
  ------------------
  |  |  303|    572|#define SC_APDU_CASE_4			0x24
  ------------------
  818|    572|	apdu.data = cmdbuff;
  819|    572|	apdu.datalen = 4;
  820|    572|	apdu.lc = 4;
  821|    572|	apdu.le = count;
  822|    572|	apdu.resplen = count;
  823|    572|	apdu.resp = buf;
  824|       |
  825|    572|	r = sc_transmit_apdu(card, &apdu);
  826|    572|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    572|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    572|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    572|	int _ret = (r); \
  |  |  |  |  168|    572|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 562]
  |  |  |  |  ------------------
  |  |  |  |  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|    572|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 562]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|       |
  828|    562|	r =  sc_check_sw(card, apdu.sw1, apdu.sw2);
  829|    562|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    562|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (829:6): [True: 299, False: 263]
  ------------------
  830|    299|		LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|    299|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    299|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    299|	int _ret = (r); \
  |  |  |  |  168|    299|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 62, False: 237]
  |  |  |  |  ------------------
  |  |  |  |  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|    299|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 237]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  831|    299|	}
  832|       |
  833|    500|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    500|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    500|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    500|	int _ret = r; \
  |  |  |  |  155|    500|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12, False: 488]
  |  |  |  |  ------------------
  |  |  |  |  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|    488|	} else { \
  |  |  |  |  159|    488|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    488|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    488|	} \
  |  |  |  |  162|    500|	return _ret; \
  |  |  |  |  163|    500|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  834|    500|}
card-sc-hsm.c:sc_hsm_init:
 1802|    118|{
 1803|       |#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE) && defined(_WIN32)
 1804|       |	char expanded_val[PATH_MAX];
 1805|       |	size_t expanded_len = PATH_MAX;
 1806|       |#endif
 1807|    118|	int flags,ext_flags;
 1808|    118|	sc_file_t *file = NULL;
 1809|    118|	sc_path_t path;
 1810|    118|	sc_hsm_private_data_t *priv = NULL;
 1811|       |
 1812|    118|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    118|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    118|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    118|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    118|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 118]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1813|       |
 1814|    118|	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|    118|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  107|    118|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |   93|    118|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1815|    118|			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  134|    118|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  138|    118|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  139|    118|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
              			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  140|    118|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 1816|    118|			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  146|    118|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  147|    118|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  148|    118|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
 1817|       |
 1818|    118|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1819|    118|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
 1820|    118|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1821|    118|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
 1822|    118|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
 1823|       |
 1824|    118|	flags = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|    118|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1825|    118|		SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|    118|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 1826|    118|		SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|    118|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    118|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 1827|    118|		SC_ALGORITHM_ECDSA_HASH_SHA1|
  ------------------
  |  |  176|    118|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|    118|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
 1828|    118|		SC_ALGORITHM_ECDSA_HASH_SHA224|
  ------------------
  |  |  177|    118|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|    118|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
 1829|    118|		SC_ALGORITHM_ECDSA_HASH_SHA256|
  ------------------
  |  |  178|    118|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|    118|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
 1830|    118|		SC_ALGORITHM_ECDSA_HASH_SHA384|
  ------------------
  |  |  179|    118|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|    118|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
 1831|    118|		SC_ALGORITHM_ECDSA_HASH_SHA512|
  ------------------
  |  |  180|    118|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|    118|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
 1832|    118|		SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    118|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1833|       |
 1834|    118|	ext_flags = SC_ALGORITHM_EXT_EC_F_P|
  ------------------
  |  |  198|    118|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
 1835|    118|			SC_ALGORITHM_EXT_EC_ECPARAMETERS|
  ------------------
  |  |  200|    118|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
 1836|    118|			SC_ALGORITHM_EXT_EC_NAMEDCURVE|
  ------------------
  |  |  201|    118|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
 1837|    118|			SC_ALGORITHM_EXT_EC_UNCOMPRESES|
  ------------------
  |  |  202|    118|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 1838|    118|			SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    118|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1839|    118|	_sc_card_add_ec_alg(card, 192, flags, ext_flags, NULL);
 1840|    118|	_sc_card_add_ec_alg(card, 224, flags, ext_flags, NULL);
 1841|    118|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1842|    118|	_sc_card_add_ec_alg(card, 320, flags, ext_flags, NULL);
 1843|    118|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 1844|    118|	_sc_card_add_ec_alg(card, 512, flags, ext_flags, NULL);
 1845|    118|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 1846|       |
 1847|    118|	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    118|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  547|    118|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    118|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1848|       |
 1849|       |	// APDU Size limits
 1850|       |	//   JCOP 2.4.1r3           1462
 1851|       |	//   JCOP 2.4.2r3           1454
 1852|       |	//   JCOP 3                 1232
 1853|       |	//   JCOP 4                 1454
 1854|       |	//   MicroSD with JCOP 3    478 / 506 - handled in reader-pcsc.c
 1855|       |	//   Reiner SCT             1014 - handled in reader-pcsc.c
 1856|       |	//
 1857|       |	// Note, that these are limits for the whole APDU, but the semantics of max_send_size
 1858|       |	// is the size of the APDU send buffer so to get the right value from them, we need
 1859|       |	// to subtract APDU headers (CLA, INS, P1, P2, Lc (3B)), 7 bytes altogether for
 1860|       |	// class 3 APDU
 1861|       |	// (or 9 bytes for case 4 when we pass in >255 B data and expect return of more than 255 B)
 1862|       |
 1863|       |	// Use JCOP 3 (smallest unhandled by reader limitation) card limits for sending
 1864|       |	// And make it 9 smaller to make sure we fit the rest of the APDU.
 1865|    118|	card->max_send_size = 1232 - 9;
 1866|       |	// Assume that card supports sending with extended length APDU and without limit
 1867|    118|	card->max_recv_size = 0;
 1868|       |
 1869|    118|	if (card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1869:6): [True: 0, False: 118]
  ------------------
 1870|    118|			|| card->type == SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1870:7): [True: 116, False: 2]
  ------------------
 1871|    116|		card->max_recv_size = 0x0630;	// SoC Proxy forces this limit
 1872|    116|	} else {
 1873|       |		// Adjust to the limits set by the reader
 1874|      2|		if (card->reader->max_send_size < card->max_send_size) {
  ------------------
  |  Branch (1874:7): [True: 2, False: 0]
  ------------------
 1875|      2|			if (18 >= card->reader->max_send_size)
  ------------------
  |  Branch (1875:8): [True: 2, False: 0]
  ------------------
 1876|      2|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1877|       |
 1878|       |			// 17 byte header and TLV because of odd ins in UPDATE BINARY
 1879|      0|			card->max_send_size = card->reader->max_send_size - 17;
 1880|      0|		}
 1881|       |
 1882|      0|		if (0 < card->reader->max_recv_size) {
  ------------------
  |  Branch (1882:7): [True: 0, False: 0]
  ------------------
 1883|      0|			if (3 >= card->reader->max_recv_size)
  ------------------
  |  Branch (1883:8): [True: 0, False: 0]
  ------------------
 1884|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1885|      0|			card->max_recv_size = card->reader->max_recv_size - 2;
 1886|      0|		}
 1887|      0|	}
 1888|       |
 1889|    116|	priv = card->drv_data;
 1890|    116|	if (!priv) {
  ------------------
  |  Branch (1890:6): [True: 116, False: 0]
  ------------------
 1891|    116|		priv = calloc(1, sizeof(sc_hsm_private_data_t));
 1892|    116|		if (!priv)
  ------------------
  |  Branch (1892:7): [True: 0, False: 116]
  ------------------
 1893|    116|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1894|    116|		card->drv_data = priv;
 1895|    116|	}
 1896|       |
 1897|    116|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    116|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1898|    116|	if (sc_hsm_select_file_ex(card, &path, 0, &file) == SC_SUCCESS
  ------------------
  |  |   28|    232|#define SC_SUCCESS				0
  ------------------
  |  Branch (1898:6): [True: 56, False: 60]
  ------------------
 1899|     56|			&& file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1899:7): [True: 56, False: 0]
  |  Branch (1899:15): [True: 6, False: 50]
  |  Branch (1899:34): [True: 5, False: 1]
  ------------------
 1900|      5|		static char card_name[SC_MAX_APDU_BUFFER_SIZE];
 1901|      5|		u8 type = 0xFF;
 1902|      5|		u8 major = file->prop_attr[file->prop_attr_len - 2];
 1903|      5|		u8 minor = file->prop_attr[file->prop_attr_len - 1];
 1904|      5|		char p00[] = "SmartCard-HSM Applet for JCOP";
 1905|      5|		char p01[] = "SmartCard-HSM Demo Applet for JCOP";
 1906|      5|		char *p = "SmartCard-HSM";
 1907|      5|		if (file->prop_attr_len >= 3) {
  ------------------
  |  Branch (1907:7): [True: 4, False: 1]
  ------------------
 1908|      4|			type = file->prop_attr[file->prop_attr_len - 3];
 1909|      4|		}
 1910|      5|		switch (type) {
 1911|      1|			case 0x00:
  ------------------
  |  Branch (1911:4): [True: 1, False: 4]
  ------------------
 1912|      1|				p = p00;
 1913|      1|				break;
 1914|      1|			case 0x01:
  ------------------
  |  Branch (1914:4): [True: 1, False: 4]
  ------------------
 1915|      1|				p = p01;
 1916|      1|				break;
 1917|      3|			default:
  ------------------
  |  Branch (1917:4): [True: 3, False: 2]
  ------------------
 1918|      3|				break;
 1919|      5|		}
 1920|      5|		snprintf(card_name, sizeof card_name, "%s version %u.%u", p, major, minor);
 1921|      5|		card->name = card_name;
 1922|       |
 1923|      5|		if (file->prop_attr[1] & 0x04) {
  ------------------
  |  Branch (1923:7): [True: 3, False: 2]
  ------------------
 1924|      3|			card->caps |= SC_CARD_CAP_SESSION_PIN;
  ------------------
  |  |  563|      3|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
 1925|      3|		}
 1926|      5|	}
 1927|    116|	sc_file_free(file);
 1928|       |
 1929|    116|	priv->EF_C_DevAut = NULL;
 1930|    116|	priv->EF_C_DevAut_len = 0;
 1931|       |
 1932|    116|#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE)
 1933|    116|	EAC_init();
 1934|       |#ifdef _WIN32
 1935|       |	expanded_len = ExpandEnvironmentStringsA(CVCDIR, expanded_val, sizeof expanded_val);
 1936|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1937|       |		EAC_set_cvc_default_dir(expanded_val);
 1938|       |#else
 1939|    116|	EAC_set_cvc_default_dir(CVCDIR);
  ------------------
  |  |    8|    116|#define CVCDIR "/usr/etc/eac/cvc"
  ------------------
 1940|    116|#endif
 1941|    116|#endif
 1942|       |
 1943|    116|	return 0;
 1944|    116|}
card-sc-hsm.c:sc_hsm_finish:
 1949|    116|{
 1950|    116|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1951|    116|#ifdef ENABLE_SM
 1952|    116|	sc_sm_stop(card);
 1953|    116|#endif
 1954|    116|	if (priv) {
  ------------------
  |  Branch (1954:6): [True: 116, False: 0]
  ------------------
 1955|    116|		free(priv->serialno);
 1956|    116|		sc_file_free(priv->dffcp);
 1957|    116|		free(priv->EF_C_DevAut);
 1958|    116|	}
 1959|    116|	free(priv);
 1960|       |
 1961|    116|	return SC_SUCCESS;
  ------------------
  |  |   28|    116|#define SC_SUCCESS				0
  ------------------
 1962|    116|}
card-sc-hsm.c:sc_hsm_card_ctl:
 1773|     12|{
 1774|     12|	switch (cmd) {
  ------------------
  |  Branch (1774:10): [True: 12, False: 0]
  ------------------
 1775|     12|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1775:2): [True: 12, False: 0]
  ------------------
 1776|     12|		return sc_hsm_get_serialnr(card, (sc_serial_number_t *)ptr);
 1777|      0|	case SC_CARDCTL_PKCS11_INIT_TOKEN:
  ------------------
  |  Branch (1777:2): [True: 0, False: 12]
  ------------------
 1778|      0|		return sc_hsm_init_token(card, (sc_cardctl_pkcs11_init_token_t *)ptr);
 1779|      0|	case SC_CARDCTL_PKCS11_INIT_PIN:
  ------------------
  |  Branch (1779:2): [True: 0, False: 12]
  ------------------
 1780|      0|		return sc_hsm_init_pin(card, (sc_cardctl_pkcs11_init_pin_t *)ptr);
 1781|      0|	case SC_CARDCTL_SC_HSM_GENERATE_KEY:
  ------------------
  |  Branch (1781:2): [True: 0, False: 12]
  ------------------
 1782|      0|		return sc_hsm_generate_keypair(card, (sc_cardctl_sc_hsm_keygen_info_t *)ptr);
 1783|      0|	case SC_CARDCTL_SC_HSM_INITIALIZE:
  ------------------
  |  Branch (1783:2): [True: 0, False: 12]
  ------------------
 1784|      0|		return sc_hsm_initialize(card, (sc_cardctl_sc_hsm_init_param_t *)ptr);
 1785|      0|	case SC_CARDCTL_SC_HSM_MANAGE_KEY_DOMAIN:
  ------------------
  |  Branch (1785:2): [True: 0, False: 12]
  ------------------
 1786|      0|		return sc_hsm_manage_key_domain(card, (sc_cardctl_sc_hsm_key_domain_t *)ptr);
 1787|      0|	case SC_CARDCTL_SC_HSM_WRAP_KEY:
  ------------------
  |  Branch (1787:2): [True: 0, False: 12]
  ------------------
 1788|      0|		return sc_hsm_wrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1789|      0|	case SC_CARDCTL_SC_HSM_UNWRAP_KEY:
  ------------------
  |  Branch (1789:2): [True: 0, False: 12]
  ------------------
 1790|      0|		return sc_hsm_unwrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1791|      0|	case SC_CARDCTL_SC_HSM_REGISTER_PUBLIC_KEY:
  ------------------
  |  Branch (1791:2): [True: 0, False: 12]
  ------------------
 1792|      0|		return sc_hsm_register_public_key(card, ptr);
 1793|      0|	case SC_CARDCTL_SC_HSM_PUBLIC_KEY_AUTH_STATUS:
  ------------------
  |  Branch (1793:2): [True: 0, False: 12]
  ------------------
 1794|      0|		return sc_hsm_public_key_auth_status(card, ptr);
 1795|     12|	}
 1796|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1797|     12|}
card-sc-hsm.c:sc_hsm_get_serialnr:
 1195|     12|{
 1196|     12|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1197|       |
 1198|     12|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     12|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     12|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1199|       |
 1200|     12|	if (!priv->serialno && 0 == strcmp(card->ctx->app_name, "opensc-tool")) {
  ------------------
  |  Branch (1200:6): [True: 12, False: 0]
  |  Branch (1200:25): [True: 0, False: 12]
  ------------------
 1201|       |		/* sc-hsm initializes the serial number via its PKCS#15 layer.
 1202|       |		 * Create and destroy a dummy card to get this initialized.  Only do
 1203|       |		 * this for `opensc-tool --serial` to avoid unnecessary card commands
 1204|       |		 * in all other cases. */
 1205|      0|		sc_pkcs15_card_t *p15card = NULL;
 1206|      0|		(void)sc_pkcs15_bind(card, NULL, &p15card);
 1207|      0|		sc_pkcs15_unbind(p15card);
 1208|      0|	}
 1209|       |
 1210|     12|	if (!priv->serialno) {
  ------------------
  |  Branch (1210:6): [True: 12, False: 0]
  ------------------
 1211|     12|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|     12|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1212|     12|	}
 1213|       |
 1214|      0|	serial->len = strlen(priv->serialno);
 1215|      0|	if (serial->len > sizeof(serial->value))
  ------------------
  |  Branch (1215:6): [True: 0, False: 0]
  ------------------
 1216|      0|		serial->len = sizeof(serial->value);
 1217|       |
 1218|      0|	memcpy(serial->value, priv->serialno, serial->len);
 1219|       |
 1220|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1221|      0|}
card-sc-hsm.c:sc_hsm_pin_cmd:
  620|     15|{
  621|     15|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  622|     15|	sc_apdu_t apdu;
  623|     15|	u8 cmdbuff[16];
  624|     15|#ifdef ENABLE_SM
  625|     15|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  626|     15|#endif
  627|     15|	int r;
  628|     15|	int cmd = data->cmd;
  629|     15|	size_t pin2_len = data->pin2.len;
  630|       |
  631|     15|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|     15|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (631:6): [True: 0, False: 15]
  ------------------
  632|       |		/* First, perform a standard VERIFY */
  633|      0|		data->cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  634|       |		/* we assign pin2.len to 0 early on so that in case of an error we are
  635|       |		 * not exiting with an undefined session PIN */
  636|      0|		data->pin2.len = 0;
  637|      0|	}
  638|       |
  639|     15|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|     15|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (639:6): [True: 0, False: 15]
  ------------------
  640|      0|		   	&& (data->cmd == SC_PIN_CMD_CHANGE)
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (640:10): [True: 0, False: 0]
  ------------------
  641|      0|		   	&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (641:10): [True: 0, False: 0]
  ------------------
  642|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (642:8): [True: 0, False: 0]
  |  Branch (642:28): [True: 0, False: 0]
  ------------------
  643|      0|		return sc_hsm_soc_change(card, data);
  644|     15|	} else if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|     15|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (644:13): [True: 0, False: 15]
  ------------------
  645|      0|		   	&& (data->cmd == SC_PIN_CMD_UNBLOCK)
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (645:10): [True: 0, False: 0]
  ------------------
  646|      0|		   	&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (646:10): [True: 0, False: 0]
  ------------------
  647|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (647:8): [True: 0, False: 0]
  |  Branch (647:28): [True: 0, False: 0]
  ------------------
  648|      0|		return sc_hsm_soc_unblock(card, data);
  649|      0|	}
  650|       |
  651|     15|#ifdef ENABLE_SM
  652|       |	/* For contactless cards always establish a secure channel before PIN
  653|       |	 * verification. Also, Session PIN generation requires SM. */
  654|     15|	if ((card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (654:7): [True: 0, False: 15]
  ------------------
  655|     15|				|| card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (655:8): [True: 15, False: 0]
  ------------------
  656|      0|				|| card->reader->uid.len || cmd == SC_PIN_CMD_GET_SESSION_PIN)
  ------------------
  |  |  419|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (656:8): [True: 0, False: 0]
  |  Branch (656:33): [True: 0, False: 0]
  ------------------
  657|     15|			&& (data->cmd != SC_PIN_CMD_GET_INFO)) {
  ------------------
  |  |  418|     15|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (657:7): [True: 3, False: 12]
  ------------------
  658|      3|		struct sc_pin_cmd_data check_sm_pin_data;
  659|      3|		memset(&check_sm_pin_data, 0, sizeof(check_sm_pin_data));
  660|      3|		check_sm_pin_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|      3|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  661|      3|		check_sm_pin_data.pin_type = data->pin_type;
  662|      3|		check_sm_pin_data.pin_reference = data->pin_reference;
  663|       |
  664|      3|		r = SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|      3|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  665|      3|		if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|      3|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (665:7): [True: 0, False: 3]
  ------------------
  666|       |			/* check if the existing SM channel is still valid */
  667|      0|			r = sc_pin_cmd(card, &check_sm_pin_data);
  668|      0|		}
  669|      3|		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   83|      6|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
              		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   59|      3|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  |  Branch (669:7): [True: 0, False: 3]
  |  Branch (669:46): [True: 3, False: 0]
  ------------------
  670|       |			/* need to establish a new SM channel */
  671|      3|			LOG_TEST_RET(card->ctx,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|      3|					sc_hsm_perform_chip_authentication(card),
  673|      3|					"Could not perform chip authentication");
  674|      3|		}
  675|      3|	}
  676|     12|#endif
  677|       |
  678|     12|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|     12|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (678:6): [True: 0, False: 12]
  ------------------
  679|      0|			&& (data->cmd == SC_PIN_CMD_VERIFY)
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (679:7): [True: 0, False: 0]
  ------------------
  680|      0|			&& (data->pin_reference == 0x81)
  ------------------
  |  Branch (680:7): [True: 0, False: 0]
  ------------------
  681|      0|			&& (!data->pin1.data || data->pin1.len <= 0)) {
  ------------------
  |  Branch (681:8): [True: 0, False: 0]
  |  Branch (681:28): [True: 0, False: 0]
  ------------------
  682|      0|		r = sc_hsm_soc_biomatch(card, data);
  683|     12|	} else {
  684|     12|		if ((data->cmd == SC_PIN_CMD_VERIFY) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  415|     12|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (684:7): [True: 0, False: 12]
  |  Branch (684:43): [True: 0, False: 0]
  ------------------
  685|      0|			if (data->pin1.len != 16)
  ------------------
  |  Branch (685:8): [True: 0, False: 0]
  ------------------
  686|      0|				return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  687|       |
  688|       |			// Save SO PIN for later use in sc_hsm_init_pin()
  689|      0|			r = sc_hsm_encode_sopin(data->pin1.data, priv->sopin);
  690|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  691|       |
  692|      0|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  693|      0|		}
  694|       |
  695|     12|		if ((data->cmd == SC_PIN_CMD_CHANGE) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  416|     12|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (695:7): [True: 0, False: 12]
  |  Branch (695:43): [True: 0, False: 0]
  ------------------
  696|      0|			if ((data->pin1.len != 16) || (data->pin2.len != 16))
  ------------------
  |  Branch (696:8): [True: 0, False: 0]
  |  Branch (696:34): [True: 0, False: 0]
  ------------------
  697|      0|				return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  698|       |
  699|      0|			r = sc_hsm_encode_sopin(data->pin1.data, cmdbuff);
  700|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  701|       |
  702|      0|			r = sc_hsm_encode_sopin(data->pin2.data, cmdbuff + 8);
  703|      0|			LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  704|       |
  705|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, 0x00, data->pin_reference);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  706|      0|			apdu.data = cmdbuff;
  707|      0|			apdu.datalen = sizeof(cmdbuff);
  708|      0|			apdu.lc = 16;
  709|      0|			apdu.resplen = 0;
  710|      0|			data->apdu = &apdu;
  711|      0|		}
  712|       |
  713|     12|#ifdef ENABLE_SM
  714|     12|		if ((data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|     12|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (714:7): [True: 12, False: 0]
  ------------------
  715|     12|				&& (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT)) {
  ------------------
  |  |   47|     12|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (715:8): [True: 0, False: 12]
  ------------------
  716|       |			/* JCOP's SM accelerator is incapable of using case 1 APDU in SM */
  717|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x20, 0x00, data->pin_reference);
  ------------------
  |  |  301|      0|#define SC_APDU_CASE_2			0x22
  ------------------
  718|      0|			apdu.resp = rbuf;
  719|      0|			apdu.resplen = sizeof rbuf;
  720|      0|			data->apdu = &apdu;
  721|      0|		}
  722|     12|#endif
  723|       |
  724|     12|		data->pin1.offset = 5;
  725|     12|		data->pin2.offset = 5;
  726|       |
  727|     12|		r = (*iso_ops->pin_cmd)(card, data);
  728|     12|		data->apdu = NULL;
  729|     12|	}
  730|     12|	LOG_TEST_RET(card->ctx, r, "Verification 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: 6, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|       |
  732|      6|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|      6|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (732:6): [True: 0, False: 6]
  ------------------
  733|       |		/* reset data->cmd to its original value */
  734|      0|		data->cmd = SC_PIN_CMD_GET_SESSION_PIN;
  ------------------
  |  |  419|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  735|      0|		if (data->pin_reference == 0x81) {
  ------------------
  |  Branch (735:7): [True: 0, False: 0]
  ------------------
  736|      0|			u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  737|      0|#ifdef ENABLE_SM
  738|      0|			if (card->sm_ctx.sm_mode != SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (738:8): [True: 0, False: 0]
  ------------------
  739|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  740|      0|						"Session PIN generation only supported in SM");
  741|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|      0|			}
  743|       |#else
  744|       |			sc_log(card->ctx,
  745|       |					"Session PIN generation only supported in SM");
  746|       |			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  747|       |#endif
  748|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x5A, 0x01, data->pin_reference);
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  749|      0|			apdu.cla = 0x80;
  750|      0|			apdu.resp = recvbuf;
  751|      0|			apdu.resplen = sizeof recvbuf;
  752|      0|			apdu.le = 0;
  753|      0|			if (sc_transmit_apdu(card, &apdu) != SC_SUCCESS
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (753:8): [True: 0, False: 0]
  ------------------
  754|      0|					|| sc_check_sw(card, apdu.sw1, apdu.sw2) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (754:9): [True: 0, False: 0]
  ------------------
  755|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  756|      0|						"Generating session PIN failed");
  757|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  758|      0|			}
  759|      0|			if (data->pin2.data && pin2_len > 0) {
  ------------------
  |  Branch (759:8): [True: 0, False: 0]
  |  Branch (759:27): [True: 0, False: 0]
  ------------------
  760|      0|				if (pin2_len >= apdu.resplen) {
  ------------------
  |  Branch (760:9): [True: 0, False: 0]
  ------------------
  761|      0|					memcpy((unsigned char *) data->pin2.data, apdu.resp,
  762|      0|							apdu.resplen);
  763|      0|					data->pin2.len = apdu.resplen;
  764|      0|				} else {
  765|      0|					sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  766|      0|							"Buffer too small for session PIN");
  767|      0|				}
  768|      0|			}
  769|      0|		} else {
  770|      0|			sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  771|      0|					"Session PIN not supported for this PIN (0x%02X)",
  772|      0|					data->pin_reference);
  773|      0|		}
  774|      0|	}
  775|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|      6|}
card-sc-hsm.c:sc_hsm_perform_chip_authentication:
  492|      3|{
  493|      3|	int r, protocol;
  494|      3|	sc_path_t path;
  495|      3|	u8 all_certs[1024];
  496|      3|	EAC_CTX *ctx = NULL;
  497|      3|	size_t all_certs_len = sizeof all_certs, left, device_cert_len, issuer_cert_len;
  498|      3|	const unsigned char *cert = all_certs, *device_cert, *issuer_cert;
  499|      3|	BUF_MEM *comp_pub_key = NULL;
  500|      3|	sc_cvc_t cvc_device, cvc_issuer;
  501|       |	/* this is only needed to call sc_pkcs15emu_sc_hsm_decode_cvc */
  502|      3|	sc_pkcs15_card_t p15card;
  503|      3|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  504|       |	/* we know that sc_pkcs15emu_sc_hsm_decode_cvc does not require anything
  505|       |	 * else to be initialized than p15card->card */
  506|      3|	p15card.card = card;
  507|       |
  508|      3|	memset(&cvc_device, 0, sizeof(cvc_device));
  509|      3|	memset(&cvc_issuer, 0, sizeof(cvc_issuer));
  510|       |
  511|       |
  512|      3|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (512:6): [True: 0, False: 3]
  |  Branch (512:27): [True: 0, False: 0]
  ------------------
  513|      0|		all_certs_len = priv->EF_C_DevAut_len;
  514|      0|		cert = priv->EF_C_DevAut;
  515|      3|	} else {
  516|       |		/* get issuer and device certificate from the card */
  517|      3|		r = sc_path_set(&path, SC_PATH_TYPE_FILE_ID, (u8 *) "\x2F\x02", 2, 0, 0);
  ------------------
  |  |  117|      3|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  518|      3|		if (r < 0)
  ------------------
  |  Branch (518:7): [True: 0, False: 3]
  ------------------
  519|      0|			goto err;
  520|      3|		r = sc_select_file(card, &path, NULL);
  521|      3|		if (r < 0)
  ------------------
  |  Branch (521:7): [True: 1, False: 2]
  ------------------
  522|      1|			goto err;
  523|      2|		r = sc_read_binary(card, 0, all_certs, all_certs_len, 0);
  524|      2|		if (r < 0)
  ------------------
  |  Branch (524:7): [True: 1, False: 1]
  ------------------
  525|      1|			goto err;
  526|      1|		if (r == 0) {
  ------------------
  |  Branch (526:7): [True: 1, False: 0]
  ------------------
  527|      1|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  528|      1|			goto err;
  529|      1|		}
  530|       |
  531|      0|		all_certs_len = r;
  532|       |
  533|       |		/* save EF_C_DevAut for further use */
  534|      0|		cert = realloc(priv->EF_C_DevAut, all_certs_len);
  535|      0|		if (cert) {
  ------------------
  |  Branch (535:7): [True: 0, False: 0]
  ------------------
  536|      0|			memcpy((unsigned char *) cert, all_certs, all_certs_len);
  537|      0|			priv->EF_C_DevAut = (unsigned char *) cert;
  538|      0|			priv->EF_C_DevAut_len = all_certs_len;
  539|      0|		}
  540|       |
  541|      0|		cert = all_certs;
  542|      0|	}
  543|      0|	left = all_certs_len;
  544|       |
  545|      0|	device_cert = cert;
  546|      0|	r = sc_pkcs15emu_sc_hsm_decode_cvc(&p15card, &cert, &left, &cvc_device);
  547|      0|	if (r < 0)
  ------------------
  |  Branch (547:6): [True: 0, False: 0]
  ------------------
  548|      0|		goto err;
  549|      0|	device_cert_len = all_certs_len - left;
  550|       |
  551|      0|	issuer_cert = cert;
  552|      0|	r = sc_pkcs15emu_sc_hsm_decode_cvc(&p15card, &cert, &left, &cvc_issuer);
  553|      0|	if (r < 0)
  ------------------
  |  Branch (553:6): [True: 0, False: 0]
  ------------------
  554|      0|		goto err;
  555|      0|	issuer_cert_len = all_certs_len - device_cert_len - left;
  556|       |
  557|      0|	ctx = EAC_CTX_new();
  558|      0|	if (!ctx) {
  ------------------
  |  Branch (558:6): [True: 0, False: 0]
  ------------------
  559|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  560|      0|		goto err;
  561|      0|	}
  562|       |
  563|       |	/* FIXME set flags with opensc.conf */
  564|      0|	TA_disable_checks(ctx);
  565|      0|	CA_disable_passive_authentication(ctx);
  566|       |
  567|       |	/* check all CVCs given of the document's pki */
  568|      0|	if (!TA_STEP2_import_certificate(ctx, issuer_cert, issuer_cert_len)
  ------------------
  |  Branch (568:6): [True: 0, False: 0]
  ------------------
  569|      0|			|| !TA_STEP2_import_certificate(ctx, device_cert, device_cert_len)) {
  ------------------
  |  Branch (569:7): [True: 0, False: 0]
  ------------------
  570|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  571|      0|		goto err;
  572|      0|	}
  573|       |
  574|       |	/* XXX on older JCOPs only NID_id_CA_ECDH_3DES_CBC_CBC may be
  575|       |	 * supported. The card does not export its capabilities. We hardcode
  576|       |	 * NID_id_CA_ECDH_AES_CBC_CMAC_128 here, because we don't have the older
  577|       |	 * cards in production. */
  578|      0|	protocol = NID_id_CA_ECDH_AES_CBC_CMAC_128;
  579|       |
  580|       |	/* initialize CA domain parameter with the document's public key */
  581|      0|	if (!EAC_CTX_init_ca(ctx, protocol, 8)) {
  ------------------
  |  Branch (581:6): [True: 0, False: 0]
  ------------------
  582|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  583|      0|		goto err;
  584|      0|	}
  585|      0|	EVP_PKEY_free(ctx->ca_ctx->ka_ctx->key);
  586|      0|	if (!EVP_PKEY_up_ref(ctx->ta_ctx->pub_key)) {
  ------------------
  |  Branch (586:6): [True: 0, False: 0]
  ------------------
  587|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  588|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  589|      0|		goto err;
  590|      0|	}
  591|      0|	ctx->ca_ctx->ka_ctx->key = ctx->ta_ctx->pub_key;
  592|       |
  593|       |	/* generate keys for CA */
  594|      0|	comp_pub_key = TA_STEP3_generate_ephemeral_key(ctx);
  595|      0|	r = perform_chip_authentication_ex(card, ctx,
  596|      0|			cvc_device.publicPoint, cvc_device.publicPointlen);
  597|       |
  598|      3|err:
  599|      3|	if (r < 0)
  ------------------
  |  Branch (599:6): [True: 3, False: 0]
  ------------------
  600|      3|		EAC_CTX_clear_free(ctx);
  601|      3|	if (comp_pub_key)
  ------------------
  |  Branch (601:6): [True: 0, False: 3]
  ------------------
  602|      0|		BUF_MEM_free(comp_pub_key);
  603|      3|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_device);
  604|      3|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_issuer);
  605|       |
  606|      3|	return r;
  607|      0|}

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

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

sc_get_srbeid_driver:
  305|  14.1k|{
  306|       |	/* Save ISO ops for delegation, then override what we handle. */
  307|  14.1k|	iso_ops = sc_get_iso7816_driver()->ops;
  308|  14.1k|	srbeid_ops = *iso_ops;
  309|  14.1k|	srbeid_ops.match_card = srbeid_match_card;
  310|  14.1k|	srbeid_ops.init = srbeid_init;
  311|  14.1k|	srbeid_ops.select_file = srbeid_select_file;
  312|  14.1k|	srbeid_ops.set_security_env = srbeid_set_security_env;
  313|  14.1k|	srbeid_ops.compute_signature = srbeid_compute_signature;
  314|  14.1k|	srbeid_ops.decipher = srbeid_decipher;
  315|       |
  316|  14.1k|	return &srbeid_drv;
  317|  14.1k|}
card-srbeid.c:srbeid_match_card:
   72|  6.51k|{
   73|  6.51k|	int i = _sc_match_atr(card, srbeid_atrs, &card->type);
   74|  6.51k|	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   30|      0|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
              	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 0, False: 6.51k]
  |  Branch (74:16): [True: 0, False: 0]
  ------------------
   75|      0|		card->name = srbeid_atrs[i].name;
   76|      0|		return 1;
   77|      0|	}
   78|  6.51k|	return 0;
   79|  6.51k|}

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

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

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

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

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

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

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

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

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

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

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

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

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

iasecc_sm_initialize:
  270|    214|{
  271|    214|	struct sc_context *ctx = card->ctx;
  272|    214|#ifdef ENABLE_SM
  273|    214|	struct sm_info *sm_info = &card->sm_ctx.info;
  274|    214|	struct sm_cwa_session *cwa_session = &sm_info->session.cwa;
  275|    214|	struct sc_remote_data rdata;
  276|    214|	int rv;
  277|       |
  278|    214|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    214|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    214|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    214|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    214|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 214]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|    214|	strlcpy(sm_info->config_section, card->sm_ctx.config_section, sizeof(sm_info->config_section));
  ------------------
  |  |   43|    214|#define strlcpy _strlcpy
  ------------------
  281|    214|	sm_info->cmd = cmd;
  282|    214|	sm_info->serialnr = card->serialnr;
  283|    214|	sm_info->card_type = card->type;
  284|    214|	sm_info->sm_type = SM_TYPE_CWA14890;
  ------------------
  |  |   39|    214|#define SM_TYPE_CWA14890	0x400
  ------------------
  285|       |
  286|    214|	rv = iasecc_sm_se_mutual_authentication(card, se_num);
  287|    214|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() MUTUAL AUTHENTICATION failed");
  ------------------
  |  |  174|    214|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    214|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    214|	int _ret = (r); \
  |  |  |  |  168|    214|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 214, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    214|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  288|       |
  289|      0|	rv = sc_get_challenge(card, cwa_session->card_challenge, SM_SMALL_CHALLENGE_LEN);
  ------------------
  |  |   85|      0|#define SM_SMALL_CHALLENGE_LEN	8
  ------------------
  290|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() GET CHALLENGE failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|      0|	sc_remote_data_init(&rdata);
  293|       |
  294|      0|	rv = sm_save_sc_context(card, sm_info);
  295|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() cannot save current context");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  296|       |
  297|      0|	if (!card->sm_ctx.module.ops.initialize)
  ------------------
  |  Branch (297:6): [True: 0, False: 0]
  ------------------
  298|      0|		LOG_TEST_RET(ctx, SC_ERROR_SM_NOT_INITIALIZED, "iasecc_sm_initialize() no SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|      0|	rv = card->sm_ctx.module.ops.initialize(ctx, sm_info, &rdata);
  300|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() INITIALIZE failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|       |
  302|       |
  303|      0|	if (rdata.length == 1)   {
  ------------------
  |  Branch (303:6): [True: 0, False: 0]
  ------------------
  304|      0|		rdata.data->flags |= SC_REMOTE_APDU_FLAG_RETURN_ANSWER;
  ------------------
  |  |  386|      0|#define SC_REMOTE_APDU_FLAG_RETURN_ANSWER	0x02
  ------------------
  305|      0|		rdata.data->apdu.flags &= ~SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|      0|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  306|      0|	}
  307|      0|	else   {
  308|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "TODO: SM init with more then one APDU");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|      0|	}
  310|       |
  311|      0|	cwa_session->mdata_len = sizeof(cwa_session->mdata);
  312|      0|	rv = iasecc_sm_transmit_apdus (card, &rdata, cwa_session->mdata, &cwa_session->mdata_len);
  313|      0|	if (rv == SC_ERROR_PIN_CODE_INCORRECT)
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (313:6): [True: 0, False: 0]
  ------------------
  314|      0|		sc_log(ctx, "SM initialization failed, %i tries left", (rdata.data + rdata.length - 1)->apdu.sw2 & 0x0F);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  315|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() transmit APDUs failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  316|       |
  317|      0|	rdata.free(&rdata);
  318|       |
  319|      0|	sc_log(ctx, "MA data(len:%zu) '%s'", cwa_session->mdata_len,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  320|      0|			sc_dump_hex(cwa_session->mdata, cwa_session->mdata_len));
  321|      0|	if (cwa_session->mdata_len != 0x48)
  ------------------
  |  Branch (321:6): [True: 0, False: 0]
  ------------------
  322|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "iasecc_sm_initialize() invalid MUTUAL AUTHENTICATE result data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  323|       |
  324|      0|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|       |#else
  326|       |	LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "built without support of Secure-Messaging");
  327|       |	return SC_ERROR_NOT_SUPPORTED;
  328|       |#endif
  329|      0|}
iasecc_sm_read_binary:
  586|    214|{
  587|    214|	struct sc_context *ctx = card->ctx;
  588|    214|#ifdef ENABLE_SM
  589|    214|	struct sm_info *sm_info = &card->sm_ctx.info;
  590|    214|	struct sc_remote_data rdata;
  591|    214|	struct iasecc_sm_cmd_update_binary cmd_data;
  592|    214|	int rv;
  593|       |
  594|    214|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    214|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    214|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    214|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    214|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 214]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  595|    214|	sc_log(ctx, "SM read binary: acl:%X, offs:%zu, count:%zu", se_num, offs, count);
  ------------------
  |  |   71|    214|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  596|       |
  597|    214|	rv = iasecc_sm_initialize(card, se_num, SM_CMD_FILE_READ);
  ------------------
  |  |   56|    214|#define SM_CMD_FILE_READ		0x201
  ------------------
  598|    214|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM INITIALIZE failed");
  ------------------
  |  |  174|    214|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    214|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    214|	int _ret = (r); \
  |  |  |  |  168|    214|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 214, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    214|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  599|       |
  600|      0|	cmd_data.offs = offs;
  601|      0|	cmd_data.count = count;
  602|      0|	sm_info->cmd_data = &cmd_data;
  603|       |
  604|      0|	sc_remote_data_init(&rdata);
  605|      0|	rv = iasecc_sm_cmd(card, &rdata);
  606|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM 'READ BINARY' failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  607|       |
  608|      0|	sc_log(ctx, "IAS/ECC decode answer() rdata length %i", rdata.length);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  609|       |
  610|      0|	rv = sm_release (card, &rdata, buff, count);
  611|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM release failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|       |
  613|      0|	rdata.free(&rdata);
  614|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|       |#else
  616|       |	LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "built without support of Secure-Messaging");
  617|       |	return SC_ERROR_NOT_SUPPORTED;
  618|       |#endif
  619|      0|}
iasecc-sm.c:iasecc_sm_se_mutual_authentication:
  222|    214|{
  223|    214|	struct sc_context *ctx = card->ctx;
  224|    214|	struct sm_info *sm_info = &card->sm_ctx.info;
  225|    214|	struct iasecc_se_info se;
  226|    214|	struct sc_crt *crt =  &sm_info->session.cwa.params.crt_at;
  227|    214|	struct sc_apdu apdu;
  228|    214|	unsigned char sbuf[0x100];
  229|    214|	int rv, offs;
  230|       |
  231|    214|	memset(&se, 0, sizeof(se));
  232|       |
  233|    214|	se.reference = se_num;
  234|    214|	crt->usage = IASECC_UQB_AT_MUTUAL_AUTHENTICATION;
  ------------------
  |  |  127|    214|#define IASECC_UQB_AT_MUTUAL_AUTHENTICATION	0xC0
  ------------------
  235|    214|	crt->tag = IASECC_CRT_TAG_AT;
  ------------------
  |  |  104|    214|#define IASECC_CRT_TAG_AT	0xA4
  ------------------
  236|       |
  237|    214|	rv = iasecc_se_get_info(card, &se);
  238|    214|	LOG_TEST_RET(ctx, rv, "Get SE info error");
  ------------------
  |  |  174|    214|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    214|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    214|	int _ret = (r); \
  |  |  |  |  168|    214|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 186, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  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|    214|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  239|       |
  240|     28|	rv = iasecc_se_get_crt(card, &se, crt);
  241|     28|	sc_file_free(se.df);
  242|     28|	LOG_TEST_RET(ctx, rv, "Cannot get authentication CRT");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|  36.7k|{
   37|  36.7k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (37:6): [True: 0, False: 36.7k]
  |  Branch (37:22): [True: 0, False: 36.7k]
  ------------------
   38|      0|		return;
   39|      0|	}
   40|       |
   41|  36.7k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (41:6): [True: 554, False: 36.1k]
  ------------------
   42|       |		/* The lower layers will automatically do chaining */
   43|    554|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    554|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   44|    554|	}
   45|       |
   46|  36.7k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (46:6): [True: 2.85k, False: 33.8k]
  ------------------
   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.85k|		apdu->le = sc_get_max_recv_size(card);
   50|  2.85k|	}
   51|  36.7k|}
encode_do_data:
  177|  7.23k|{
  178|  7.23k|	unsigned char offset_buffer[2];
  179|  7.23k|	size_t offset_buffer_len = sizeof offset_buffer;
  180|  7.23k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  181|  7.23k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  182|       |
  183|  7.23k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (183:6): [True: 0, False: 7.23k]
  ------------------
  184|  7.23k|		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|  7.23k|	offset_buffer[0] = (u8) (idx >> 8);
  186|  7.23k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  187|  7.23k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  188|       |
  189|  7.23k|	if (data && data_len) {
  ------------------
  |  Branch (189:6): [True: 0, False: 7.23k]
  |  Branch (189:14): [True: 0, False: 0]
  ------------------
  190|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  191|  7.23k|	} else {
  192|  7.23k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  193|  7.23k|	}
  194|       |
  195|  7.23k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  7.23k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.23k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.23k|	int _ret = (r); \
  |  |  |  |  168|  7.23k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 7.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|  7.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|  7.23k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  197|  7.23k|			"sc_asn1_encode() failed");
  198|       |
  199|  7.23k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.23k|#define SC_SUCCESS				0
  ------------------
  200|  7.23k|}
decode_do_data:
  205|  5.51k|{
  206|  5.51k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  207|  5.51k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  208|       |
  209|  5.51k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  210|  5.51k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  211|       |
  212|  5.51k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  5.51k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.51k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.51k|	int _ret = (r); \
  |  |  |  |  168|  5.51k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 247, False: 5.27k]
  |  |  |  |  ------------------
  |  |  |  |  169|    247|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    247|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    247|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    247|		return _ret; \
  |  |  |  |  172|    247|	} \
  |  |  |  |  173|  5.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|  5.27k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  214|  5.27k|			"sc_asn1_decode() failed");
  215|       |
  216|  5.27k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  5.27k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (216:6): [True: 3.23k, False: 2.04k]
  ------------------
  217|  3.23k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  3.23k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  218|       |
  219|  2.04k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.04k|#define SC_SUCCESS				0
  ------------------
  220|  5.27k|}
iso7816_build_pin_apdu:
 1183|  1.03k|{
 1184|  1.03k|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1185|  1.03k|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  1.03k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1186|       |
 1187|  1.03k|	switch (data->pin_type) {
 1188|    901|	case SC_AC_CHV:
  ------------------
  |  |  151|    901|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1188:2): [True: 901, False: 137]
  ------------------
 1189|       |		/* fall through */
 1190|    926|	case SC_AC_SESSION:
  ------------------
  |  |  159|    926|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1190:2): [True: 25, False: 1.01k]
  ------------------
 1191|    955|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|    955|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1191:2): [True: 29, False: 1.00k]
  ------------------
 1192|    955|		break;
 1193|     83|	default:
  ------------------
  |  Branch (1193:2): [True: 83, False: 955]
  ------------------
 1194|     83|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     83|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1195|  1.03k|	}
 1196|       |
 1197|    955|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  422|    955|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1197:6): [True: 221, False: 734]
  ------------------
 1198|    221|		pad = 1;
 1199|    955|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  421|    955|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1199:6): [True: 0, False: 955]
  ------------------
 1200|      0|		use_pin_pad = 1;
 1201|       |
 1202|    955|	data->pin1.offset = 5;
 1203|       |
 1204|    955|	switch (data->cmd) {
 1205|    242|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|    242|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1205:2): [True: 242, False: 713]
  ------------------
 1206|    242|		ins = 0x20;
 1207|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1208|    242|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1208:7): [True: 0, False: 242]
  |  Branch (1208:30): [True: 0, False: 0]
  ------------------
 1209|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1210|    242|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1210:7): [True: 13, False: 229]
  ------------------
 1211|     13|			return r;
 1212|    229|		len = r;
 1213|    229|		break;
 1214|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1214:2): [True: 0, False: 955]
  ------------------
 1215|      0|		ins = 0x24;
 1216|      0|		if (data->pin1.len != 0 || (use_pin_pad && !( data->flags & SC_PIN_CMD_IMPLICIT_CHANGE))) {
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  |  Branch (1216:7): [True: 0, False: 0]
  |  Branch (1216:31): [True: 0, False: 0]
  |  Branch (1216:46): [True: 0, False: 0]
  ------------------
 1217|      0|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1217:8): [True: 0, False: 0]
  ------------------
 1218|      0|				return r;
 1219|      0|			len += r;
 1220|      0|		}
 1221|      0|		else {
 1222|       |			/* implicit test */
 1223|      0|			p1 = 1;
 1224|      0|		}
 1225|       |
 1226|      0|		data->pin2.offset = data->pin1.offset + len;
 1227|      0|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1227:7): [True: 0, False: 0]
  ------------------
 1228|      0|			return r;
 1229|       |		/* Special case - where provided the old PIN on the command line
 1230|       |		 * but expect the new one to be entered on the keypad.
 1231|       |		 */
 1232|      0|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1232:7): [True: 0, False: 0]
  |  Branch (1232:25): [True: 0, False: 0]
  ------------------
 1233|      0|			sc_log(card->ctx, "Special case - initial pin provided - but new pin asked on keypad");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1234|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1235|      0|		};
 1236|      0|		len += r;
 1237|      0|		break;
 1238|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1238:2): [True: 0, False: 955]
  ------------------
 1239|      0|		ins = 0x2C;
 1240|      0|		if (data->pin1.len != 0 || (use_pin_pad && !( data->flags & SC_PIN_CMD_IMPLICIT_CHANGE))) {
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  |  Branch (1240:7): [True: 0, False: 0]
  |  Branch (1240:31): [True: 0, False: 0]
  |  Branch (1240:46): [True: 0, False: 0]
  ------------------
 1241|      0|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1241:8): [True: 0, False: 0]
  ------------------
 1242|      0|				return r;
 1243|      0|			len += r;
 1244|      0|		} else {
 1245|      0|			p1 |= 0x02;
 1246|      0|		}
 1247|       |
 1248|      0|		if (data->pin2.len != 0 || use_pin_pad) {
  ------------------
  |  Branch (1248:7): [True: 0, False: 0]
  |  Branch (1248:30): [True: 0, False: 0]
  ------------------
 1249|      0|			data->pin2.offset = data->pin1.offset + len;
 1250|      0|			if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1250:8): [True: 0, False: 0]
  ------------------
 1251|      0|				return r;
 1252|      0|			len += r;
 1253|      0|		} else {
 1254|      0|			p1 |= 0x01;
 1255|      0|		}
 1256|      0|		if (p1 == 0x03) {
  ------------------
  |  Branch (1256:7): [True: 0, False: 0]
  ------------------
 1257|       |			/* No data to send or to receive */
 1258|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1259|      0|		}
 1260|      0|		break;
 1261|    713|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    713|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1261:2): [True: 713, False: 242]
  ------------------
 1262|    713|		ins = 0x20;
 1263|       |		/* No data to send or to receive */
 1264|    713|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|    713|#define SC_APDU_CASE_1			0x01
  ------------------
 1265|    713|		break;
 1266|      0|	default:
  ------------------
  |  Branch (1266:2): [True: 0, False: 955]
  ------------------
 1267|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1268|    955|	}
 1269|       |
 1270|    942|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1271|    942|	apdu->lc = len;
 1272|    942|	apdu->datalen = len;
 1273|    942|	apdu->data = buf;
 1274|    942|	apdu->resplen = 0;
 1275|       |
 1276|    942|	return 0;
 1277|    955|}
iso7816_select_aid:
 1395|  12.7k|{
 1396|  12.7k|	struct sc_context *ctx = card->ctx;
 1397|  12.7k|	struct sc_apdu apdu;
 1398|  12.7k|	int rv;
 1399|       |
 1400|  12.7k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  12.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  12.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  12.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 12.7k]
  |  |  ------------------
  ------------------
 1401|       |
 1402|  12.7k|	sc_format_apdu(card, &apdu, resp == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, resp == NULL ? 0x0C : 0x00);
  ------------------
  |  |  293|  6.30k|#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|  6.40k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1402:30): [True: 6.30k, False: 6.40k]
  |  Branch (1402:102): [True: 6.30k, False: 6.40k]
  ------------------
 1403|  12.7k|	apdu.lc = reqlen;
 1404|  12.7k|	apdu.data = req;
 1405|  12.7k|	apdu.datalen = reqlen;
 1406|  12.7k|	apdu.resp = resp;
 1407|  12.7k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1407:17): [True: 6.30k, False: 6.40k]
  ------------------
 1408|  12.7k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1408:12): [True: 6.30k, False: 6.40k]
  ------------------
 1409|       |
 1410|  12.7k|	rv = sc_transmit_apdu(card, &apdu);
 1411|  12.7k|	if (resplen)
  ------------------
  |  Branch (1411:6): [True: 6.40k, False: 6.30k]
  ------------------
 1412|  6.40k|		*resplen = apdu.resplen;
 1413|  12.7k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  12.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  12.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  12.7k|	int _ret = (r); \
  |  |  |  |  168|  12.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 116, False: 12.5k]
  |  |  |  |  ------------------
  |  |  |  |  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|  12.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1414|       |
 1415|  12.5k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1416|  12.5k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  12.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.5k|	int _ret = r; \
  |  |  |  |  155|  12.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  8.28k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.28k, False: 4.31k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.5k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.5k|	return _ret; \
  |  |  |  |  163|  12.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1417|  12.5k|}
sc_get_iso7816_driver:
 1485|   476k|{
 1486|   476k|	return &iso_driver;
 1487|   476k|}
iso7816.c:no_match:
 1431|  6.55k|{
 1432|  6.55k|	return 0;
 1433|  6.55k|}
iso7816.c:iso7816_read_record:
  225|  13.4k|{
  226|  13.4k|	struct sc_apdu apdu;
  227|  13.4k|	int r;
  228|       |	/* XXX maybe use some bigger buffer */
  229|  13.4k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  230|  13.4k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  231|  13.4k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  232|       |
  233|  13.4k|	if (rec_nr > 0xFF)
  ------------------
  |  Branch (233:6): [True: 2, False: 13.4k]
  ------------------
  234|  13.4k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|       |
  236|  13.4k|	if (idx == 0) {
  ------------------
  |  Branch (236:6): [True: 6.18k, False: 7.23k]
  ------------------
  237|  6.18k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  6.18k|#define SC_APDU_CASE_2			0x22
  ------------------
  238|  6.18k|		apdu.le = count;
  239|  6.18k|		apdu.resplen = count;
  240|  6.18k|		apdu.resp = buf;
  241|  7.23k|	} else {
  242|  7.23k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  243|  7.23k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  7.23k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  7.23k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  7.23k|	int _ret = (r); \
  |  |  |  |  178|  7.23k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 7.23k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  7.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 7.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|       |
  245|  7.23k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  7.23k|#define SC_APDU_CASE_4			0x24
  ------------------
  246|  7.23k|		apdu.lc = encoded_data_len;
  247|  7.23k|		apdu.datalen = encoded_data_len;
  248|  7.23k|		apdu.data = encoded_data;
  249|  7.23k|		apdu.le = sizeof resp;
  250|  7.23k|		apdu.resplen = sizeof resp;
  251|  7.23k|		apdu.resp = resp;
  252|  7.23k|	}
  253|  13.4k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|  13.4k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  254|  13.4k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|  13.4k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (254:6): [True: 13.4k, False: 0]
  ------------------
  255|  13.4k|		apdu.p2 |= 0x04;
  256|       |
  257|  13.4k|	iso7816_fixup_transceive_length(card, &apdu);
  258|  13.4k|	r = sc_transmit_apdu(card, &apdu);
  259|  13.4k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  13.4k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  13.4k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  13.4k|	int _ret = (r); \
  |  |  |  |  178|  13.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 811, False: 12.6k]
  |  |  |  |  ------------------
  |  |  |  |  179|    811|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    811|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    811|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    811|		goto err; \
  |  |  |  |  182|    811|	} \
  |  |  |  |  183|  13.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 12.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|  12.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  261|  12.6k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  12.6k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  12.6k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  12.6k|	int _ret = (r); \
  |  |  |  |  178|  12.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1.52k, False: 11.0k]
  |  |  |  |  ------------------
  |  |  |  |  179|  1.52k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.52k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  1.52k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  1.52k|		goto err; \
  |  |  |  |  182|  1.52k|	} \
  |  |  |  |  183|  12.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 11.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|       |
  263|  11.0k|	if (idx == 0) {
  ------------------
  |  Branch (263:6): [True: 5.55k, False: 5.51k]
  ------------------
  264|  5.55k|		r = (int)apdu.resplen;
  265|  5.55k|	} else {
  266|  5.51k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  267|  5.51k|				&decoded_data, &decoded_data_len);
  268|  5.51k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  5.51k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.51k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.51k|	int _ret = (r); \
  |  |  |  |  178|  5.51k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 3.47k, False: 2.04k]
  |  |  |  |  ------------------
  |  |  |  |  179|  3.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|  3.47k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  3.47k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  3.47k|		goto err; \
  |  |  |  |  182|  3.47k|	} \
  |  |  |  |  183|  5.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.04k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  2.04k|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (269:7): [True: 1.38k, False: 651]
  ------------------
  270|  1.38k|			count = decoded_data_len;
  271|  1.38k|		}
  272|  2.04k|		memcpy(buf, decoded_data, count);
  273|  2.04k|		r = (int)count;
  274|  2.04k|	}
  275|       |
  276|  13.4k|err:
  277|  13.4k|	free(encoded_data);
  278|  13.4k|	free(decoded_data);
  279|  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: 6.09k, False: 7.31k]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.09k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.81k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.81k, False: 282]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.31k|	} else { \
  |  |  |  |  159|  7.31k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  7.31k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  7.31k|	} \
  |  |  |  |  162|  13.4k|	return _ret; \
  |  |  |  |  163|  13.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|  13.4k|}
iso7816.c:iso7816_select_file:
  629|  44.1k|{
  630|  44.1k|	struct sc_context *ctx;
  631|  44.1k|	struct sc_apdu apdu;
  632|  44.1k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  633|  44.1k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  634|  44.1k|	int r, pathtype;
  635|  44.1k|	size_t pathlen;
  636|  44.1k|	int select_mf = 0;
  637|  44.1k|	struct sc_file *file = NULL;
  638|  44.1k|	const u8 *buffer;
  639|  44.1k|	size_t buffer_len;
  640|  44.1k|	unsigned int cla, tag;
  641|       |
  642|  44.1k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (642:6): [True: 0, False: 44.1k]
  |  Branch (642:22): [True: 0, False: 44.1k]
  ------------------
  643|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  644|      0|	}
  645|  44.1k|	ctx = card->ctx;
  646|  44.1k|	memcpy(path, in_path->value, in_path->len);
  647|  44.1k|	pathlen = in_path->len;
  648|  44.1k|	pathtype = in_path->type;
  649|       |
  650|  44.1k|	if (in_path->aid.len) {
  ------------------
  |  Branch (650:6): [True: 1.73k, False: 42.3k]
  ------------------
  651|  1.73k|		if (!pathlen) {
  ------------------
  |  Branch (651:7): [True: 1.45k, False: 276]
  ------------------
  652|  1.45k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  653|  1.45k|			pathlen = in_path->aid.len;
  654|  1.45k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.45k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  655|  1.45k|		} else {
  656|       |			/* First, select the application */
  657|    276|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|    276|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  658|    276|			apdu.data = in_path->aid.value;
  659|    276|			apdu.datalen = in_path->aid.len;
  660|    276|			apdu.lc = in_path->aid.len;
  661|       |
  662|    276|			r = sc_transmit_apdu(card, &apdu);
  663|    276|			LOG_TEST_RET(ctx, r, "APDU transmit 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: 3, False: 273]
  |  |  |  |  ------------------
  |  |  |  |  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|    276|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 273]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  664|    273|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  665|    273|			if (r)
  ------------------
  |  Branch (665:8): [True: 203, False: 70]
  ------------------
  666|    273|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  667|       |
  668|     70|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    140|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (668:8): [True: 70, False: 0]
  ------------------
  669|      0|					|| pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (669:9): [True: 0, False: 0]
  ------------------
  670|     70|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|     70|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  671|     70|		}
  672|  1.73k|	}
  673|       |
  674|  43.8k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  43.8k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  675|       |
  676|  43.8k|	switch (pathtype) {
  677|  7.95k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  7.95k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (677:2): [True: 7.95k, False: 35.9k]
  ------------------
  678|  7.95k|		apdu.p1 = 0;
  679|  7.95k|		if (pathlen != 2)
  ------------------
  |  Branch (679:7): [True: 0, False: 7.95k]
  ------------------
  680|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  681|  7.95k|		break;
  682|  19.7k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  19.7k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (682:2): [True: 19.7k, False: 24.1k]
  ------------------
  683|  19.7k|		apdu.p1 = 4;
  684|  19.7k|		break;
  685|  16.0k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  16.0k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (685:2): [True: 16.0k, False: 27.8k]
  ------------------
  686|  16.0k|		apdu.p1 = 8;
  687|  16.0k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (687:7): [True: 15.9k, False: 108]
  |  Branch (687:23): [True: 11.1k, False: 4.81k]
  ------------------
  688|  11.1k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (688:8): [True: 3.13k, False: 7.98k]
  ------------------
  689|  3.13k|				select_mf = 1;
  690|  3.13k|				apdu.p1 = 0;
  691|  3.13k|				break;
  692|  3.13k|			}
  693|  7.98k|			path += 2;
  694|  7.98k|			pathlen -= 2;
  695|  7.98k|		}
  696|  12.9k|		break;
  697|  12.9k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|     70|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (697:2): [True: 70, False: 43.8k]
  ------------------
  698|     70|		apdu.p1 = 9;
  699|     70|		break;
  700|     98|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|     98|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (700:2): [True: 98, False: 43.8k]
  ------------------
  701|     98|		apdu.p1 = 3;
  702|     98|		pathlen = 0;
  703|     98|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|     98|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  704|     98|		break;
  705|      0|	default:
  ------------------
  |  Branch (705:2): [True: 0, False: 43.8k]
  ------------------
  706|      0|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  707|  43.8k|	}
  708|  43.8k|	apdu.lc = pathlen;
  709|  43.8k|	apdu.data = path;
  710|  43.8k|	apdu.datalen = pathlen;
  711|       |
  712|  43.8k|	if (file_out != NULL) {
  ------------------
  |  Branch (712:6): [True: 27.7k, False: 16.1k]
  ------------------
  713|  27.7k|		apdu.p2 = 0;		/* first record, return FCI */
  714|  27.7k|		apdu.resp = buf;
  715|  27.7k|		apdu.resplen = sizeof(buf);
  716|  27.7k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (716:13): [True: 1.11k, False: 26.6k]
  ------------------
  717|  27.7k|	}
  718|  16.1k|	else {
  719|  16.1k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  720|  16.1k|		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|  32.2k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (720:14): [True: 0, False: 16.1k]
  ------------------
  721|  16.1k|	}
  722|       |
  723|  43.8k|	r = sc_transmit_apdu(card, &apdu);
  724|  43.8k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  43.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  43.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  43.8k|	int _ret = (r); \
  |  |  |  |  168|  43.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 541, False: 43.3k]
  |  |  |  |  ------------------
  |  |  |  |  169|    541|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    541|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    541|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    541|		return _ret; \
  |  |  |  |  172|    541|	} \
  |  |  |  |  173|  43.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 43.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  725|  43.3k|	if (file_out == NULL) {
  ------------------
  |  Branch (725:6): [True: 16.0k, False: 27.2k]
  ------------------
  726|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  727|  16.0k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  728|  16.0k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (728:7): [True: 126, False: 15.9k]
  |  Branch (728:27): [True: 13, False: 113]
  ------------------
  729|     13|			apdu.p2 = 0x00;
  730|     13|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     13|#define SC_SUCCESS				0
  ------------------
  |  Branch (730:8): [True: 12, False: 1]
  ------------------
  731|     12|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  732|     13|		}
  733|  16.0k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (733:7): [True: 0, False: 16.0k]
  ------------------
  734|  16.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  735|  16.0k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  16.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.0k|	int _ret = r; \
  |  |  |  |  155|  16.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  11.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.8k, False: 4.19k]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.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|  16.0k|	return _ret; \
  |  |  |  |  163|  16.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  736|  16.0k|	}
  737|       |
  738|  27.2k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  739|  27.2k|	if (r)
  ------------------
  |  Branch (739:6): [True: 15.7k, False: 11.5k]
  ------------------
  740|  27.2k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  15.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  15.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  15.7k|	int _ret = r; \
  |  |  |  |  155|  15.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  15.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  15.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 15.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  15.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  15.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|  15.7k|	return _ret; \
  |  |  |  |  163|  15.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  741|       |
  742|  11.5k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (742:6): [True: 11.5k, False: 0]
  |  Branch (742:18): [True: 2.33k, False: 9.17k]
  ------------------
  743|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  744|  2.33k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.83k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (744:7): [True: 499, False: 1.83k]
  |  Branch (744:20): [True: 1.57k, False: 265]
  ------------------
  745|  2.07k|			file = sc_file_new();
  746|  2.07k|			if (file == NULL)
  ------------------
  |  Branch (746:8): [True: 0, False: 2.07k]
  ------------------
  747|  2.07k|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  748|  2.07k|			file->path = *in_path;
  749|       |
  750|  2.07k|			*file_out = file;
  751|  2.07k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.07k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.07k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.07k|	int _ret = r; \
  |  |  |  |  155|  2.07k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.07k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.07k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.07k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.07k|	return _ret; \
  |  |  |  |  163|  2.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  752|  2.07k|		}
  753|  2.33k|	}
  754|       |
  755|  9.43k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (755:6): [True: 276, False: 9.16k]
  ------------------
  756|  9.43k|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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|    276|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 276, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  757|  9.16k|	switch (apdu.resp[0]) {
  758|  8.07k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  8.07k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (758:2): [True: 8.07k, False: 1.08k]
  ------------------
  759|  8.86k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  8.86k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (759:2): [True: 788, False: 8.37k]
  ------------------
  760|  8.86k|		file = sc_file_new();
  761|  8.86k|		if (file == NULL)
  ------------------
  |  Branch (761:7): [True: 0, False: 8.86k]
  ------------------
  762|  8.86k|			LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  763|  8.86k|		file->path = *in_path;
  764|  8.86k|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (764:7): [True: 0, False: 8.86k]
  ------------------
  765|      0|			sc_file_free(file);
  766|      0|			LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  767|      0|		}
  768|  8.86k|		buffer = apdu.resp;
  769|  8.86k|		r = sc_asn1_read_tag(&buffer, apdu.resplen, &cla, &tag, &buffer_len);
  770|  8.86k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  8.86k|#define SC_SUCCESS				0
  ------------------
  |  Branch (770:7): [True: 7.64k, False: 1.21k]
  ------------------
  771|  7.64k|			card->ops->process_fci(card, file, buffer, buffer_len);
  772|  8.86k|		*file_out = file;
  773|  8.86k|		break;
  774|     81|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (774:2): [True: 81, False: 9.07k]
  ------------------
  775|     81|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     81|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     81|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     81|	int _ret = r; \
  |  |  |  |  155|     81|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     81|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     81|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     81|	return _ret; \
  |  |  |  |  163|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|    219|	default:
  ------------------
  |  Branch (776:2): [True: 219, False: 8.94k]
  ------------------
  777|    219|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    219|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    219|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    219|	int _ret = r; \
  |  |  |  |  155|    219|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 219, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    219|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    219|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 219, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    219|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    219|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    219|	return _ret; \
  |  |  |  |  163|    219|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|  9.16k|	}
  779|       |
  780|  8.86k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.86k|#define SC_SUCCESS				0
  ------------------
  781|  9.16k|}
iso7816.c:iso7816_get_response:
  904|  19.8k|{
  905|  19.8k|	struct sc_apdu apdu = {0};
  906|  19.8k|	int r;
  907|  19.8k|	size_t rlen;
  908|       |
  909|       |	/* request at most max_recv_size bytes */
  910|  19.8k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (910:6): [True: 578, False: 19.2k]
  ------------------
  911|    578|		rlen = sc_get_max_recv_size(card);
  912|  19.2k|	else
  913|  19.2k|		rlen = *count;
  914|       |
  915|  19.8k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|  19.8k|#define SC_APDU_CASE_2			0x22
  ------------------
  916|  19.8k|	apdu.le      = rlen;
  917|  19.8k|	apdu.resplen = rlen;
  918|  19.8k|	apdu.resp    = buf;
  919|       |	/* don't call GET RESPONSE recursively */
  920|  19.8k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  19.8k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  921|       |
  922|  19.8k|	r = sc_transmit_apdu(card, &apdu);
  923|  19.8k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  19.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  19.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  19.8k|	int _ret = (r); \
  |  |  |  |  168|  19.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 559, False: 19.2k]
  |  |  |  |  ------------------
  |  |  |  |  169|    559|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    559|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    559|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    559|		return _ret; \
  |  |  |  |  172|    559|	} \
  |  |  |  |  173|  19.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  924|       |
  925|  19.2k|	*count = apdu.resplen;
  926|       |
  927|  19.2k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (927:6): [True: 5.13k, False: 14.1k]
  ------------------
  928|  5.13k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  5.13k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.13k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.13k|	int _ret = r; \
  |  |  |  |  155|  5.13k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.13k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.13k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.41k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.41k, False: 2.71k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.13k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.13k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  5.13k|	return _ret; \
  |  |  |  |  163|  5.13k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  929|  5.13k|	}
  930|  14.1k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (930:6): [True: 6.39k, False: 7.76k]
  |  Branch (930:26): [True: 6.06k, False: 329]
  ------------------
  931|  6.06k|		r = 0;					/* no more data to read */
  932|  8.09k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (932:11): [True: 4.44k, False: 3.64k]
  ------------------
  933|  4.44k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (933:7): [True: 2.58k, False: 1.86k]
  ------------------
  934|  3.64k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (934:11): [True: 2.23k, False: 1.41k]
  |  Branch (934:31): [True: 2.16k, False: 68]
  ------------------
  935|  2.16k|		r = 0; /* Le not reached but file/record ended */
  936|  1.47k|	else
  937|  1.47k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  938|       |
  939|  14.1k|	return r;
  940|  19.2k|}
iso7816.c:iso7816_set_security_env:
  981|    150|{
  982|    150|	struct sc_apdu apdu;
  983|    150|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  984|    150|	u8 *p;
  985|    150|	int r, locked = 0;
  986|       |
  987|    150|	if (card == NULL || env == NULL) {
  ------------------
  |  Branch (987:6): [True: 0, False: 150]
  |  Branch (987:22): [True: 0, False: 150]
  ------------------
  988|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  989|      0|	}
  990|    150|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0);
  ------------------
  |  |  293|    150|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  991|    150|	switch (env->operation) {
  992|      0|	case SC_SEC_OPERATION_AUTHENTICATE:
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (992:2): [True: 0, False: 150]
  ------------------
  993|      0|		apdu.p2 = 0xA4;
  994|      0|		break;
  995|     92|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     92|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (995:2): [True: 92, False: 58]
  ------------------
  996|     92|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   50|     92|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (996:2): [True: 0, False: 150]
  ------------------
  997|     92|		apdu.p2 = 0xB8;
  998|     92|		break;
  999|     58|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|     58|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (999:2): [True: 58, False: 92]
  ------------------
 1000|     58|		apdu.p2 = 0xB6;
 1001|     58|		break;
 1002|      0|	default:
  ------------------
  |  Branch (1002:2): [True: 0, False: 150]
  ------------------
 1003|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1004|    150|	}
 1005|    150|	p = sbuf;
 1006|    150|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|    150|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1006:6): [True: 109, False: 41]
  ------------------
 1007|    109|		*p++ = 0x80;	/* algorithm reference */
 1008|    109|		*p++ = 0x01;
 1009|    109|		*p++ = env->algorithm_ref & 0xFF;
 1010|    109|	}
 1011|    150|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   57|    150|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1011:6): [True: 0, False: 150]
  ------------------
 1012|      0|		if (env->file_ref.len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|      0|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (1012:7): [True: 0, False: 0]
  ------------------
 1013|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1014|      0|		if (sizeof(sbuf) - (p - sbuf) < env->file_ref.len + 2)
  ------------------
  |  Branch (1014:7): [True: 0, False: 0]
  ------------------
 1015|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1016|       |
 1017|      0|		*p++ = 0x81;
 1018|      0|		*p++ = (u8) env->file_ref.len;
 1019|      0|		memcpy(p, env->file_ref.value, env->file_ref.len);
 1020|      0|		p += env->file_ref.len;
 1021|      0|	}
 1022|    150|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   58|    150|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1022:6): [True: 148, False: 2]
  ------------------
 1023|    148|		if (sizeof(sbuf) - (p - sbuf) < env->key_ref_len + 2)
  ------------------
  |  Branch (1023:7): [True: 0, False: 148]
  ------------------
 1024|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1025|       |
 1026|    148|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   59|    148|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1026:7): [True: 0, False: 148]
  ------------------
 1027|      0|			*p++ = 0x83;
 1028|    148|		else
 1029|    148|			*p++ = 0x84;
 1030|    148|		if (env->key_ref_len > SC_MAX_KEYREF_SIZE)
  ------------------
  |  |   53|    148|#define SC_MAX_KEYREF_SIZE		8
  ------------------
  |  Branch (1030:7): [True: 0, False: 148]
  ------------------
 1031|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1032|    148|		*p++ = env->key_ref_len & 0xFF;
 1033|    148|		memcpy(p, env->key_ref, env->key_ref_len);
 1034|    148|		p += env->key_ref_len;
 1035|    148|	}
 1036|    150|	r = (int)(p - sbuf);
 1037|    150|	apdu.lc = r;
 1038|    150|	apdu.datalen = r;
 1039|    150|	apdu.data = sbuf;
 1040|    150|	if (se_num > 0) {
  ------------------
  |  Branch (1040:6): [True: 0, False: 150]
  ------------------
 1041|      0|		r = sc_lock(card);
 1042|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1043|      0|		locked = 1;
 1044|      0|	}
 1045|    150|	if (apdu.datalen != 0) {
  ------------------
  |  Branch (1045:6): [True: 149, False: 1]
  ------------------
 1046|    149|		r = sc_transmit_apdu(card, &apdu);
 1047|    149|		if (r) {
  ------------------
  |  Branch (1047:7): [True: 1, False: 148]
  ------------------
 1048|      1|			sc_log(card->ctx, "%s: APDU transmit failed", sc_strerror(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__
  |  |  ------------------
  ------------------
 1049|      1|			goto err;
 1050|      1|		}
 1051|    148|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1052|    148|		if (r) {
  ------------------
  |  Branch (1052:7): [True: 44, False: 104]
  ------------------
 1053|     44|			sc_log(card->ctx, "%s: Card returned error", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1054|     44|			goto err;
 1055|     44|		}
 1056|    148|	}
 1057|    105|	if (se_num <= 0) {
  ------------------
  |  Branch (1057:6): [True: 105, False: 0]
  ------------------
 1058|    105|		r = SC_SUCCESS;
  ------------------
  |  |   28|    105|#define SC_SUCCESS				0
  ------------------
 1059|    105|		goto err;
 1060|    105|	}
 1061|      0|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF2, se_num);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1062|      0|	r = sc_transmit_apdu(card, &apdu);
 1063|      0|	sc_unlock(card);
 1064|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1065|       |
 1066|      0|	return sc_check_sw(card, apdu.sw1, apdu.sw2);
 1067|    150|err:
 1068|    150|	if (locked)
  ------------------
  |  Branch (1068:6): [True: 0, False: 150]
  ------------------
 1069|      0|		sc_unlock(card);
 1070|    150|	return r;
 1071|      0|}
iso7816.c:iso7816_decipher:
 1138|     11|{
 1139|     11|	int r;
 1140|     11|	struct sc_apdu apdu;
 1141|     11|	u8 *sbuf = NULL;
 1142|       |
 1143|     11|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1143:6): [True: 0, False: 11]
  |  Branch (1143:22): [True: 0, False: 11]
  |  Branch (1143:40): [True: 0, False: 11]
  ------------------
 1144|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1145|      0|	}
 1146|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|     11|	sc_log(card->ctx, "ISO7816 decipher: in-len %zu, out-len %zu", crgram_len, outlen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1148|       |
 1149|     11|	sbuf = malloc(crgram_len + 1);
 1150|     11|	if (sbuf == NULL)
  ------------------
  |  Branch (1150:6): [True: 0, False: 11]
  ------------------
 1151|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1152|       |
 1153|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1154|       |	 * P1:  0x80  Resp: Plain value
 1155|       |	 * P2:  0x86  Cmd: Padding indicator byte followed by cryptogram */
 1156|     11|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x80, 0x86);
  ------------------
  |  |  303|     11|#define SC_APDU_CASE_4			0x24
  ------------------
 1157|     11|	apdu.resp    = out;
 1158|     11|	apdu.resplen = outlen;
 1159|     11|	apdu.le      = outlen;
 1160|       |
 1161|     11|	sbuf[0] = 0; /* padding indicator byte, 0x00 = No further indication */
 1162|     11|	memcpy(sbuf + 1, crgram, crgram_len);
 1163|     11|	apdu.data = sbuf;
 1164|     11|	apdu.lc = crgram_len + 1;
 1165|     11|	apdu.datalen = crgram_len + 1;
 1166|       |
 1167|     11|	iso7816_fixup_transceive_length(card, &apdu);
 1168|     11|	r = sc_transmit_apdu(card, &apdu);
 1169|     11|	sc_mem_clear(sbuf, crgram_len + 1);
 1170|     11|	free(sbuf);
 1171|     11|	LOG_TEST_RET(card->ctx, r, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1172|       |
 1173|     10|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1173:6): [True: 5, False: 5]
  |  Branch (1173:26): [True: 4, False: 1]
  ------------------
 1174|     10|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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|      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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1175|      6|	else
 1176|     10|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1177|     10|}
iso7816.c:iso7816_check_sw:
  111|   342k|{
  112|   342k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  113|   342k|	int i;
  114|       |
  115|       |	/* Handle special cases here */
  116|   342k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (116:6): [True: 223, False: 342k]
  ------------------
  117|    223|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|    223|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  118|    223|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|    223|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  119|    223|	}
  120|   342k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (120:6): [True: 134k, False: 208k]
  |  Branch (120:21): [True: 132k, False: 1.64k]
  ------------------
  121|   132k|		return SC_SUCCESS;
  ------------------
  |  |   28|   132k|#define SC_SUCCESS				0
  ------------------
  122|   209k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (122:6): [True: 325, False: 209k]
  |  Branch (122:22): [True: 99, False: 226]
  ------------------
  123|     99|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  124|     99|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     99|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  125|     99|	}
  126|  8.45M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (126:14): [True: 8.44M, False: 12.9k]
  ------------------
  127|  8.44M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (127:7): [True: 196k, False: 8.24M]
  ------------------
  128|   196k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   196k|#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|   196k|			return iso7816_errors[i].errorno;
  130|   196k|		}
  131|  8.44M|	}
  132|       |
  133|  12.9k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  134|  12.9k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  12.9k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  135|   209k|}
iso7816.c:iso7816_process_fci:
  431|  8.97k|{
  432|  8.97k|	struct sc_context *ctx = card->ctx;
  433|  8.97k|	const unsigned char *p, *end;
  434|  8.97k|	unsigned int cla = 0, tag = 0;
  435|  8.97k|	size_t length;
  436|       |
  437|  8.97k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  8.97k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  438|       |
  439|  8.97k|	for (p = buf, length = buflen, end = buf + buflen;
  440|  29.3k|			p < end;
  ------------------
  |  Branch (440:4): [True: 26.5k, False: 2.88k]
  ------------------
  441|  26.5k|			p += length, length = end - p) {
  442|       |
  443|  26.5k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  26.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:7): [True: 4.17k, False: 22.3k]
  ------------------
  444|  22.3k|				|| p == NULL) {
  ------------------
  |  Branch (444:8): [True: 1.91k, False: 20.4k]
  ------------------
  445|  6.08k|			break;
  446|  6.08k|		}
  447|  20.4k|		switch (cla | tag) {
  ------------------
  |  Branch (447:11): [True: 14.9k, False: 5.50k]
  ------------------
  448|  2.59k|			case 0x81:
  ------------------
  |  Branch (448:4): [True: 2.59k, False: 17.8k]
  ------------------
  449|  2.59k|				if (file->size != 0) {
  ------------------
  |  Branch (449:9): [True: 101, False: 2.49k]
  ------------------
  450|       |					/* don't overwrite existing file size excluding structural information */
  451|    101|					break;
  452|    101|				}
  453|       |				/* fall through */
  454|  4.54k|			case 0x80:
  ------------------
  |  Branch (454:4): [True: 2.05k, False: 18.3k]
  ------------------
  455|       |				/* determine the file size */
  456|  4.54k|				file->size = 0;
  457|  4.54k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (457:9): [True: 4.54k, False: 0]
  |  Branch (457:14): [True: 4.49k, False: 50]
  ------------------
  458|  4.49k|					size_t size = 0, i;
  459|  13.4k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (459:18): [True: 8.99k, False: 4.49k]
  ------------------
  460|  8.99k|						size <<= 8;
  461|  8.99k|						size |= p[i];
  462|  8.99k|					}
  463|  4.49k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  4.49k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (463:10): [True: 627, False: 3.87k]
  ------------------
  464|    627|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  220|    627|#define MAX_FILE_SIZE 65535
  ------------------
  465|    627|						sc_log(ctx, "  file size truncated, encoded length: %zu", size);
  ------------------
  |  |   71|    627|#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.87k|					} else {
  467|  3.87k|						file->size = size;
  468|  3.87k|					}
  469|  4.49k|				}
  470|       |
  471|  4.54k|				sc_log(ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   71|  4.54k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  472|  4.54k|				break;
  473|       |
  474|  2.76k|			case 0x82:
  ------------------
  |  Branch (474:4): [True: 2.76k, False: 17.6k]
  ------------------
  475|  2.76k|				if (length > 0) {
  ------------------
  |  Branch (475:9): [True: 2.41k, False: 345]
  ------------------
  476|  2.41k|					unsigned char byte = p[0];
  477|  2.41k|					const char *type;
  478|       |
  479|  2.41k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (479:24): [True: 355, False: 2.06k]
  ------------------
  480|  2.41k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 355, False: 2.06k]
  |  |  ------------------
  ------------------
  481|  2.41k|					file->ef_structure = byte & 0x07;
  482|  2.41k|					switch ((byte >> 3) & 7) {
  483|  1.39k|						case 0:
  ------------------
  |  Branch (483:7): [True: 1.39k, False: 1.02k]
  ------------------
  484|  1.39k|							type = "working EF";
  485|  1.39k|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  1.39k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  486|  1.39k|							break;
  487|    110|						case 1:
  ------------------
  |  Branch (487:7): [True: 110, False: 2.30k]
  ------------------
  488|    110|							type = "internal EF";
  489|    110|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    110|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  490|    110|							break;
  491|    207|						case 7:
  ------------------
  |  Branch (491:7): [True: 207, False: 2.21k]
  ------------------
  492|    207|							type = "DF";
  493|    207|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    207|#define SC_FILE_TYPE_DF			0x04
  ------------------
  494|    207|							break;
  495|    705|						default:
  ------------------
  |  Branch (495:7): [True: 705, False: 1.71k]
  ------------------
  496|    705|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    705|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  497|    705|							type = "unknown";
  498|    705|							break;
  499|  2.41k|					}
  500|  2.41k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   71|  2.41k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  501|  2.41k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   71|  2.41k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  502|  2.41k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   71|  2.41k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  503|       |
  504|       |					/* if possible, get additional information for non-DFs */
  505|  2.41k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  2.41k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (505:10): [True: 2.21k, False: 207]
  ------------------
  506|       |						/* max. record length for fixed- & variable-sized records */
  507|  2.21k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (507:11): [True: 501, False: 1.71k]
  |  Branch (507:25): [True: 349, False: 152]
  ------------------
  508|    349|							file->record_length = (length > 3)
  ------------------
  |  Branch (508:30): [True: 225, False: 124]
  ------------------
  509|    349|								? bebytes2ushort(p+2)
  510|    349|								: p[2];
  511|    349|							sc_log(ctx, "  record length: %zu", file->record_length);
  ------------------
  |  |   71|    349|#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|    349|						}
  513|       |
  514|       |						/* number of records */
  515|  2.21k|						if (length > 4) {
  ------------------
  |  Branch (515:11): [True: 211, False: 2.00k]
  ------------------
  516|    211|							file->record_count = (length > 5)
  ------------------
  |  Branch (516:29): [True: 75, False: 136]
  ------------------
  517|    211|								? bebytes2ushort(p+4)
  518|    211|								: p[4];
  519|    211|							sc_log(ctx, "  records: %zu", file->record_count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  520|    211|						}
  521|  2.21k|					}
  522|       |
  523|  2.41k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  2.41k|#define SC_SUCCESS				0
  ------------------
  |  Branch (523:10): [True: 0, False: 2.41k]
  ------------------
  524|      0|						sc_log(ctx, "Warning: Could not set file attributes");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  525|  2.41k|				}
  526|  2.76k|				break;
  527|       |
  528|  2.76k|			case 0x83:
  ------------------
  |  Branch (528:4): [True: 1.57k, False: 18.8k]
  ------------------
  529|  1.57k|				if (length == 2) {
  ------------------
  |  Branch (529:9): [True: 1.40k, False: 163]
  ------------------
  530|  1.40k|					file->id = (p[0] << 8) | p[1];
  531|  1.40k|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|  1.40k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  532|  1.40k|				}
  533|  1.57k|				break;
  534|       |
  535|    507|			case 0x84:
  ------------------
  |  Branch (535:4): [True: 507, False: 19.9k]
  ------------------
  536|    507|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (536:9): [True: 305, False: 202]
  |  Branch (536:23): [True: 286, False: 19]
  ------------------
  537|    286|					memcpy(file->name, p, length);
  538|    286|					file->namelen = length;
  539|       |
  540|    286|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    286|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    286|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  541|    286|					if (!file->type)
  ------------------
  |  Branch (541:10): [True: 122, False: 164]
  ------------------
  542|    122|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    122|#define SC_FILE_TYPE_DF			0x04
  ------------------
  543|    286|				}
  544|    507|				break;
  545|       |
  546|    551|			case 0x85:
  ------------------
  |  Branch (546:4): [True: 551, False: 19.8k]
  ------------------
  547|  1.10k|			case 0xA5:
  ------------------
  |  Branch (547:4): [True: 554, False: 19.8k]
  ------------------
  548|  1.10k|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|  1.10k|#define SC_SUCCESS				0
  ------------------
  |  Branch (548:9): [True: 0, False: 1.10k]
  ------------------
  549|      0|					sc_log(ctx, "Warning: Could not set proprietary file properties");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  550|      0|				}
  551|  1.10k|				break;
  552|       |
  553|  1.03k|			case 0x86:
  ------------------
  |  Branch (553:4): [True: 1.03k, False: 19.3k]
  ------------------
  554|  1.03k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.03k|#define SC_SUCCESS				0
  ------------------
  |  Branch (554:9): [True: 0, False: 1.03k]
  ------------------
  555|      0|					sc_log(ctx, "Warning: Could not set file security properties");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  556|      0|				}
  557|  1.03k|				break;
  558|       |
  559|    270|			case 0x88:
  ------------------
  |  Branch (559:4): [True: 270, False: 20.1k]
  ------------------
  560|    270|				if (length == 1) {
  ------------------
  |  Branch (560:9): [True: 67, False: 203]
  ------------------
  561|     67|					file->sid = *p;
  562|     67|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  563|     67|				}
  564|    270|				break;
  565|       |
  566|  1.98k|			case 0x8A:
  ------------------
  |  Branch (566:4): [True: 1.98k, False: 18.4k]
  ------------------
  567|  1.98k|				if (length == 1) {
  ------------------
  |  Branch (567:9): [True: 1.73k, False: 249]
  ------------------
  568|  1.73k|					switch (p[0]) {
  569|    156|						case 0:
  ------------------
  |  Branch (569:7): [True: 156, False: 1.58k]
  ------------------
  570|    156|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|    156|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  571|    156|							break;
  572|     71|						case 1:
  ------------------
  |  Branch (572:7): [True: 71, False: 1.66k]
  ------------------
  573|     71|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     71|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  574|     71|							break;
  575|     76|						case 3:
  ------------------
  |  Branch (575:7): [True: 76, False: 1.66k]
  ------------------
  576|     76|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|     76|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  577|     76|							break;
  578|     95|						case 4:
  ------------------
  |  Branch (578:7): [True: 95, False: 1.64k]
  ------------------
  579|    164|						case 6:
  ------------------
  |  Branch (579:7): [True: 69, False: 1.66k]
  ------------------
  580|    164|							file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|    164|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  581|    164|							break;
  582|    419|						case 5:
  ------------------
  |  Branch (582:7): [True: 419, False: 1.31k]
  ------------------
  583|    493|						case 7:
  ------------------
  |  Branch (583:7): [True: 74, False: 1.66k]
  ------------------
  584|    493|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    493|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  585|    493|							break;
  586|    100|						case 12:
  ------------------
  |  Branch (586:7): [True: 100, False: 1.63k]
  ------------------
  587|    172|						case 13:
  ------------------
  |  Branch (587:7): [True: 72, False: 1.66k]
  ------------------
  588|    244|						case 14:
  ------------------
  |  Branch (588:7): [True: 72, False: 1.66k]
  ------------------
  589|    312|						case 15:
  ------------------
  |  Branch (589:7): [True: 68, False: 1.66k]
  ------------------
  590|    312|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|    312|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  591|    312|							break;
  592|     66|						case 2:
  ------------------
  |  Branch (592:7): [True: 66, False: 1.67k]
  ------------------
  593|     66|							file->status = SC_FILE_STATUS_RFU_2;
  ------------------
  |  |  248|     66|#define SC_FILE_STATUS_RFU_2		0x07 /* ISO7816-4: (0x02) */
  ------------------
  594|     66|							break;
  595|     66|						case 8:
  ------------------
  |  Branch (595:7): [True: 66, False: 1.67k]
  ------------------
  596|     66|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|     66|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  597|     66|							break;
  598|     66|						case 9:
  ------------------
  |  Branch (598:7): [True: 66, False: 1.67k]
  ------------------
  599|     66|							file->status = SC_FILE_STATUS_RFU_9;
  ------------------
  |  |  250|     66|#define SC_FILE_STATUS_RFU_9		0x09 /* ISO7816-4: (0x09) */
  ------------------
  600|     66|							break;
  601|     68|						case 10:
  ------------------
  |  Branch (601:7): [True: 68, False: 1.66k]
  ------------------
  602|     68|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     68|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  603|     68|							break;
  604|     87|						case 11:
  ------------------
  |  Branch (604:7): [True: 87, False: 1.65k]
  ------------------
  605|     87|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     87|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  606|     87|							break;
  607|    112|						default:
  ------------------
  |  Branch (607:7): [True: 112, False: 1.62k]
  ------------------
  608|    112|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|    112|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  609|  1.73k|					}
  610|  1.73k|				}
  611|  1.98k|				break;
  612|       |
  613|  1.98k|			case 0x62:
  ------------------
  |  Branch (613:4): [True: 699, False: 19.7k]
  ------------------
  614|    781|			case 0x64:
  ------------------
  |  Branch (614:4): [True: 82, False: 20.3k]
  ------------------
  615|  1.02k|			case 0x6F:
  ------------------
  |  Branch (615:4): [True: 243, False: 20.1k]
  ------------------
  616|       |				/* allow nested FCP/FMD/FCI templates */
  617|  1.02k|				iso7816_process_fci(card, file, p, length);
  618|  20.4k|		}
  619|  20.4k|	}
  620|       |
  621|  8.97k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  8.97k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  622|       |
  623|  8.97k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.97k|#define SC_SUCCESS				0
  ------------------
  624|  8.97k|}
iso7816.c:iso7816_pin_cmd:
 1282|  1.17k|{
 1283|  1.17k|	struct sc_apdu local_apdu, *apdu;
 1284|  1.17k|	int r;
 1285|  1.17k|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1286|       |
 1287|  1.17k|	data->pin1.tries_left = -1;
 1288|       |
 1289|       |	/* Many cards do support PIN status queries, but some cards don't and
 1290|       |	 * mistakenly count the command as a failed PIN attempt, so for now we
 1291|       |	 * allow cards with this flag.  In future this may be reduced to a
 1292|       |	 * blocklist, subject to testing more cards. */
 1293|  1.17k|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  418|  2.34k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1293:6): [True: 928, False: 242]
  ------------------
 1294|    928|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  553|    928|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1294:6): [True: 132, False: 796]
  ------------------
 1295|    132|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   71|    132|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1296|    132|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    132|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1297|    132|	}
 1298|       |
 1299|       |	/* See if we've been called from another card driver, which is
 1300|       |	 * passing an APDU to us (this allows to write card drivers
 1301|       |	 * whose PIN functions behave "mostly like ISO" except in some
 1302|       |	 * special circumstances.
 1303|       |	 */
 1304|  1.03k|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1304:6): [True: 1.03k, False: 0]
  ------------------
 1305|  1.03k|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1306|  1.03k|		if (r < 0)
  ------------------
  |  Branch (1306:7): [True: 96, False: 942]
  ------------------
 1307|     96|			return r;
 1308|    942|		data->apdu = &local_apdu;
 1309|    942|	}
 1310|    942|	apdu = data->apdu;
 1311|       |
 1312|    942|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  421|    942|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
              	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1312:6): [True: 942, False: 0]
  |  Branch (1312:48): [True: 0, False: 0]
  ------------------
 1313|       |		/* Transmit the APDU to the card */
 1314|    942|		r = sc_transmit_apdu(card, apdu);
 1315|       |
 1316|       |		/* Clear the buffer - it may contain pins */
 1317|    942|		sc_mem_clear(sbuf, sizeof(sbuf));
 1318|    942|	}
 1319|      0|	else {
 1320|       |		/* Call the reader driver to collect
 1321|       |		 * the PIN and pass on the APDU to the card */
 1322|      0|		if (data->pin1.offset == 0) {
  ------------------
  |  Branch (1322:7): [True: 0, False: 0]
  ------------------
 1323|      0|			sc_log(card->ctx, "Card driver didn't set PIN offset");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1324|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1325|      0|		}
 1326|      0|		if (card->reader && card->reader->ops && card->reader->ops->perform_verify) {
  ------------------
  |  Branch (1326:7): [True: 0, False: 0]
  |  Branch (1326:23): [True: 0, False: 0]
  |  Branch (1326:44): [True: 0, False: 0]
  ------------------
 1327|      0|			r = card->reader->ops->perform_verify(card->reader, data);
 1328|       |			/* sw1/sw2 filled in by reader driver */
 1329|      0|		}
 1330|      0|		else {
 1331|      0|			sc_log(card->ctx, "Card reader driver does not support "
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1332|      0|					"PIN entry through reader key pad");
 1333|      0|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1334|      0|		}
 1335|      0|	}
 1336|       |
 1337|       |	/* Don't pass references to local variables up to the caller. */
 1338|    942|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1338:6): [True: 942, False: 0]
  ------------------
 1339|    942|		data->apdu = NULL;
 1340|       |
 1341|    942|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    942|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    942|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    942|	int _ret = (r); \
  |  |  |  |  168|    942|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 938]
  |  |  |  |  ------------------
  |  |  |  |  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|    942|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 938]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1342|    938|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1343|       |
 1344|    938|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    938|#define SC_SUCCESS				0
  ------------------
  |  Branch (1344:6): [True: 818, False: 120]
  ------------------
 1345|    818|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|    818|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1346|    818|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|    120|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1346:13): [True: 2, False: 118]
  ------------------
 1347|      2|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1348|      2|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      2|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1349|      2|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|      2|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1349:7): [True: 1, False: 1]
  ------------------
 1350|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1351|    118|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|    118|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1351:13): [True: 2, False: 116]
  ------------------
 1352|      2|		data->pin1.tries_left = 0;
 1353|      2|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      2|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1354|      2|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|      2|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1354:7): [True: 1, False: 1]
  ------------------
 1355|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1356|      2|	}
 1357|       |
 1358|    938|	return r;
 1359|    942|}
iso7816.c:iso7816_get_data:
 1363|    263|{
 1364|    263|	int                             r, cse;
 1365|    263|	struct sc_apdu                  apdu;
 1366|       |
 1367|    263|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1368|       |
 1369|    263|	if (buf && len)
  ------------------
  |  Branch (1369:6): [True: 263, False: 0]
  |  Branch (1369:13): [True: 263, False: 0]
  ------------------
 1370|    263|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    263|#define SC_APDU_CASE_2			0x22
  ------------------
 1371|      0|	else
 1372|      0|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1373|       |
 1374|    263|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1375|    263|	apdu.le = len;
 1376|    263|	apdu.resp = buf;
 1377|    263|	apdu.resplen = len;
 1378|    263|	r = sc_transmit_apdu(card, &apdu);
 1379|    263|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 5, False: 258]
  |  |  |  |  ------------------
  |  |  |  |  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|    263|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 258]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1380|       |
 1381|    258|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1382|    258|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  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: 63, False: 195]
  |  |  |  |  ------------------
  |  |  |  |  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|    258|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 195]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1383|       |
 1384|    195|	if (apdu.resplen > len)
  ------------------
  |  Branch (1384:6): [True: 0, False: 195]
  ------------------
 1385|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1386|    195|	else
 1387|    195|		r = (int)apdu.resplen;
 1388|       |
 1389|    195|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    195|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    195|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    195|	int _ret = r; \
  |  |  |  |  155|    195|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 167]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    167|	} else { \
  |  |  |  |  159|    167|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    167|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    167|	} \
  |  |  |  |  162|    195|	return _ret; \
  |  |  |  |  163|    195|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1390|    195|}
iso7816.c:iso7816_read_binary:
  140|  23.3k|{
  141|  23.3k|	struct sc_context *ctx = card->ctx;
  142|  23.3k|	struct sc_apdu apdu;
  143|  23.3k|	int r;
  144|       |
  145|  23.3k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (145:6): [True: 5, False: 23.3k]
  ------------------
  146|      5|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  147|      5|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      5|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  148|      5|	}
  149|       |
  150|  23.3k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  23.3k|#define SC_APDU_CASE_2			0x22
  ------------------
  151|  23.3k|	apdu.le = count;
  152|  23.3k|	apdu.resplen = count;
  153|  23.3k|	apdu.resp = buf;
  154|       |
  155|  23.3k|	iso7816_fixup_transceive_length(card, &apdu);
  156|  23.3k|	r = sc_transmit_apdu(card, &apdu);
  157|  23.3k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  23.3k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  23.3k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  23.3k|	int _ret = (r); \
  |  |  |  |  168|  23.3k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 692, False: 22.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|    692|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    692|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    692|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    692|		return _ret; \
  |  |  |  |  172|    692|	} \
  |  |  |  |  173|  23.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|       |
  159|  22.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  160|  22.6k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  45.2k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  21.1k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (160:6): [True: 1.47k, False: 21.1k]
  |  Branch (160:40): [True: 80, False: 21.0k]
  ------------------
  161|  22.6k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  1.55k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.55k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.55k|	int _ret = r; \
  |  |  |  |  155|  1.55k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 563, False: 996]
  |  |  |  |  ------------------
  |  |  |  |  156|    563|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 563]
  |  |  |  |  ------------------
  |  |  |  |  157|    563|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    996|	} else { \
  |  |  |  |  159|    996|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    996|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    996|	} \
  |  |  |  |  162|  1.55k|	return _ret; \
  |  |  |  |  163|  1.55k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|  21.0k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  21.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  21.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  21.0k|	int _ret = (r); \
  |  |  |  |  168|  21.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.76k, False: 18.3k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.76k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.76k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.76k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.76k|		return _ret; \
  |  |  |  |  172|  2.76k|	} \
  |  |  |  |  173|  21.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  163|       |
  164|  18.3k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  18.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.3k|	int _ret = r; \
  |  |  |  |  155|  18.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 390, False: 17.9k]
  |  |  |  |  ------------------
  |  |  |  |  156|    390|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 390]
  |  |  |  |  ------------------
  |  |  |  |  157|    390|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.9k|	} else { \
  |  |  |  |  159|  17.9k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  17.9k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  17.9k|	} \
  |  |  |  |  162|  18.3k|	return _ret; \
  |  |  |  |  163|  18.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|  18.3k|}

sc_do_log:
   58|  11.9M|{
   59|  11.9M|	va_list ap;
   60|       |
   61|  11.9M|	va_start(ap, format);
   62|  11.9M|	sc_do_log_va(ctx, level, file, line, func, 0, format, ap);
   63|       |	va_end(ap);
   64|  11.9M|}
sc_do_log_color:
   67|  2.34M|{
   68|  2.34M|	va_list ap;
   69|       |
   70|  2.34M|	va_start(ap, format);
   71|  2.34M|	sc_do_log_va(ctx, level, file, line, func, color, format, ap);
   72|       |	va_end(ap);
   73|  2.34M|}
sc_do_log_openssl:
   77|      8|{
   78|      8|	BIO *bio = NULL;
   79|      8|	int length, rc;
   80|      8|	char *buffer = NULL;
   81|       |
   82|      8|	if ((bio = BIO_new(BIO_s_mem())) == NULL) {
  ------------------
  |  Branch (82:6): [True: 0, False: 8]
  ------------------
   83|      0|		sc_do_log(ctx, level, file, line, func, "Cannot log OpenSSL error");
   84|      0|		goto end;
   85|      0|	}
   86|      8|	ERR_print_errors(bio);
   87|       |
   88|      8|	length = BIO_pending(bio);
   89|      8|	if (length <= 0) {
  ------------------
  |  Branch (89:6): [True: 0, False: 8]
  ------------------
   90|       |		/* no error? */
   91|      0|		goto end;
   92|      0|	}
   93|       |	/* trailing null byte */
   94|      8|	buffer = malloc(length + 1);
   95|      8|	if (buffer == NULL) {
  ------------------
  |  Branch (95:6): [True: 0, False: 8]
  ------------------
   96|      0|		sc_do_log(ctx, level, file, line, func, "No memory!");
   97|      0|		goto end;
   98|      0|	}
   99|      8|	rc = BIO_read(bio, buffer, length);
  100|      8|	buffer[length] = '\0';
  101|      8|	if (rc <= 0) {
  ------------------
  |  Branch (101:6): [True: 0, False: 8]
  ------------------
  102|      0|		sc_do_log(ctx, level, file, line, func, "Cannot read OpenSSL error");
  103|      0|		goto end;
  104|      0|	}
  105|       |
  106|      8|	sc_do_log(ctx, level, file, line, func, "OpenSSL error\n%s", buffer);
  107|      8|end:
  108|      8|	free(buffer);
  109|      8|	BIO_free(bio);
  110|      8|}
sc_color_fprintf:
  254|  1.03M|{
  255|  1.03M|	int r;
  256|  1.03M|	va_list ap;
  257|       |
  258|  1.03M|	va_start(ap, format);
  259|  1.03M|	r = sc_color_fprintf_va(colors, ctx, stream, format, ap);
  260|  1.03M|	va_end(ap);
  261|       |
  262|  1.03M|	return r;
  263|  1.03M|}
_sc_debug_hex:
  343|   323k|{
  344|   323k|	size_t blen;
  345|   323k|	char *buf;
  346|   323k|	const char *truncated = "";
  347|       |
  348|   323k|	if (len > SC_MAX_EXT_APDU_BUFFER_SIZE) {
  ------------------
  |  |   37|   323k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
  |  Branch (348:6): [True: 0, False: 323k]
  ------------------
  349|      0|		len = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|      0|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
  350|      0|		truncated = "truncated to ";
  351|      0|	}
  352|   323k|	blen = len * 5 + 128;
  353|       |
  354|   323k|	buf = malloc(blen);
  355|   323k|	if (buf == NULL)
  ------------------
  |  Branch (355:6): [True: 0, False: 323k]
  ------------------
  356|      0|		return;
  357|       |
  358|   323k|	sc_hex_dump(data, len, buf, blen);
  359|       |
  360|   323k|	if (label)
  ------------------
  |  Branch (360:6): [True: 323k, False: 0]
  ------------------
  361|   323k|		sc_do_log(ctx, type, file, line, func, "\n%s (%s%zu byte%s):\n%s",
  362|   323k|				label, truncated, len, len == 1 ? "" : "s", buf);
  ------------------
  |  Branch (362:28): [True: 808, False: 322k]
  ------------------
  363|      0|	else
  364|      0|		sc_do_log(ctx, type, file, line, func, "%s%zu byte%s:\n%s",
  365|      0|				truncated, len, len == 1 ? "" : "s", buf);
  ------------------
  |  Branch (365:21): [True: 0, False: 0]
  ------------------
  366|       |
  367|   323k|	free(buf);
  368|   323k|}
sc_hex_dump:
  371|   323k|{
  372|   323k|	char *p = buf;
  373|   323k|	size_t p_len = len;
  374|   323k|	int lines = 0;
  375|       |
  376|   323k|	if (buf == NULL || (in == NULL && count != 0)) {
  ------------------
  |  Branch (376:6): [True: 0, False: 323k]
  |  Branch (376:22): [True: 315, False: 323k]
  |  Branch (376:36): [True: 0, False: 315]
  ------------------
  377|      0|		return;
  378|      0|	}
  379|   323k|	buf[0] = 0;
  380|   323k|	if ((count * 5) > len)
  ------------------
  |  Branch (380:6): [True: 0, False: 323k]
  ------------------
  381|      0|		return;
  382|  2.48M|	while (count) {
  ------------------
  |  Branch (382:9): [True: 2.16M, False: 323k]
  ------------------
  383|  2.16M|		char ascbuf[17];
  384|  2.16M|		size_t i;
  385|       |
  386|  34.1M|		for (i = 0; i < count && i < 16; i++) {
  ------------------
  |  Branch (386:15): [True: 33.9M, False: 248k]
  |  Branch (386:28): [True: 32.0M, False: 1.91M]
  ------------------
  387|  32.0M|			sprintf(p, "%02X ", *in);
  388|  32.0M|			if (isprint(*in))
  ------------------
  |  Branch (388:8): [True: 20.8M, False: 11.1M]
  ------------------
  389|  20.8M|				ascbuf[i] = *in;
  390|  11.1M|			else
  391|  11.1M|				ascbuf[i] = '.';
  392|  32.0M|			p += 3;
  393|  32.0M|			p_len -= 3;
  394|  32.0M|			in++;
  395|  32.0M|		}
  396|  2.16M|		count -= i;
  397|  2.16M|		ascbuf[i] = 0;
  398|  3.31M|		for (; i < 16 && lines; i++) {
  ------------------
  |  Branch (398:10): [True: 1.27M, False: 2.03M]
  |  Branch (398:20): [True: 1.15M, False: 124k]
  ------------------
  399|  1.15M|			strlcat(p, "   ", p_len);
  400|  1.15M|			p += 3;
  401|  1.15M|			p_len -= 3;
  402|  1.15M|		}
  403|  2.16M|		snprintf(p, p_len, "%s\n", ascbuf);
  404|  2.16M|		p += strlen(ascbuf) + 1;
  405|  2.16M|		p_len -= strlen(ascbuf) - 1;
  406|  2.16M|		lines++;
  407|  2.16M|	}
  408|   323k|}
sc_dump_hex:
  412|   154k|{
  413|   154k|	static char dump_buf[0x1000];
  414|   154k|	size_t ii, size = sizeof(dump_buf) - 0x10;
  415|   154k|	size_t offs = 0;
  416|       |
  417|   154k|	memset(dump_buf, 0, sizeof(dump_buf));
  418|   154k|	if (in == NULL)
  ------------------
  |  Branch (418:6): [True: 110, False: 154k]
  ------------------
  419|    110|		return dump_buf;
  420|       |
  421|   460k|	for (ii=0; ii<count; ii++) {
  ------------------
  |  Branch (421:13): [True: 306k, False: 154k]
  ------------------
  422|   306k|		if (ii && !(ii%16))   {
  ------------------
  |  Branch (422:7): [True: 267k, False: 38.9k]
  |  Branch (422:13): [True: 4.06k, False: 263k]
  ------------------
  423|  4.06k|			if (!(ii%48))
  ------------------
  |  Branch (423:8): [True: 1.16k, False: 2.89k]
  ------------------
  424|  1.16k|				snprintf(dump_buf + offs, size - offs, "\n");
  425|  2.89k|			else
  426|  2.89k|				snprintf(dump_buf + offs, size - offs, " ");
  427|  4.06k|			offs = strlen(dump_buf);
  428|  4.06k|		}
  429|       |
  430|   306k|		snprintf(dump_buf + offs, size - offs, "%02X", *(in + ii));
  431|   306k|		offs += 2;
  432|       |
  433|   306k|		if (offs > size)
  ------------------
  |  Branch (433:7): [True: 6, False: 306k]
  ------------------
  434|      6|			break;
  435|   306k|	}
  436|       |
  437|   154k|	if (ii<count)
  ------------------
  |  Branch (437:6): [True: 6, False: 154k]
  ------------------
  438|      6|		snprintf(dump_buf + offs, sizeof(dump_buf) - offs, "....\n");
  439|       |
  440|   154k|	return dump_buf;
  441|   154k|}
sc_dump_oid:
  445|  3.77k|{
  446|  3.77k|	static char dump_buf[SC_MAX_OBJECT_ID_OCTETS * 20];
  447|  3.77k|        size_t ii;
  448|       |
  449|  3.77k|	memset(dump_buf, 0, sizeof(dump_buf));
  450|  3.77k|	if (oid)
  ------------------
  |  Branch (450:6): [True: 3.77k, False: 0]
  ------------------
  451|  21.0k|		for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS && oid->value[ii] != -1; ii++)
  ------------------
  |  |   46|  42.1k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (451:14): [True: 21.0k, False: 0]
  |  Branch (451:44): [True: 17.2k, False: 3.77k]
  ------------------
  452|  17.2k|			snprintf(dump_buf + strlen(dump_buf), sizeof(dump_buf) - strlen(dump_buf), "%s%i", (ii ? "." : ""), oid->value[ii]);
  ------------------
  |  Branch (452:88): [True: 13.5k, False: 3.77k]
  ------------------
  453|       |
  454|  3.77k|	return dump_buf;
  455|  3.77k|}
log.c:sc_do_log_va:
  124|  14.2M|{
  125|       |#ifdef _WIN32
  126|       |	SYSTEMTIME st;
  127|       |#else
  128|  14.2M|	struct tm *tm;
  129|  14.2M|	struct timeval tv;
  130|  14.2M|	char time_string[40];
  131|  14.2M|#endif
  132|       |
  133|  14.2M|	if (!ctx || ctx->debug < level)
  ------------------
  |  Branch (133:6): [True: 0, False: 14.2M]
  |  Branch (133:14): [True: 14.1M, False: 160k]
  ------------------
  134|  14.1M|		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|   160k|	if (ctx->debug_file == NULL)
  ------------------
  |  Branch (143:6): [True: 0, False: 160k]
  ------------------
  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|   160k|	sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
  ------------------
  |  |   45|   160k|#define SC_COLOR_FG_GREEN		0x0002
  ------------------
              	sc_color_fprintf(SC_COLOR_FG_GREEN|SC_COLOR_BOLD,
  ------------------
  |  |   56|   160k|#define SC_COLOR_BOLD			0x8080
  ------------------
  160|   160k|			ctx, ctx->debug_file,
  161|   160k|			"P:%lu; T:0x%lu",
  162|   160k|			(unsigned long)getpid(),
  163|   160k|			(unsigned long)pthread_self());
  164|   160k|	gettimeofday (&tv, NULL);
  165|   160k|	tm = localtime (&tv.tv_sec);
  166|   160k|	strftime (time_string, sizeof(time_string), "%H:%M:%S", tm);
  167|   160k|	sc_color_fprintf(SC_COLOR_FG_GREEN,
  ------------------
  |  |   45|   160k|#define SC_COLOR_FG_GREEN		0x0002
  ------------------
  168|   160k|			ctx, ctx->debug_file,
  169|   160k|			" %s.%03ld",
  170|   160k|			time_string,
  171|   160k|			(long)tv.tv_usec / 1000);
  172|   160k|#endif
  173|       |
  174|   160k|	sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|   160k|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  175|   160k|			ctx, ctx->debug_file,
  176|   160k|			" [");
  177|   160k|	sc_color_fprintf(SC_COLOR_FG_YELLOW|SC_COLOR_BOLD,
  ------------------
  |  |   46|   160k|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
              	sc_color_fprintf(SC_COLOR_FG_YELLOW|SC_COLOR_BOLD,
  ------------------
  |  |   56|   160k|#define SC_COLOR_BOLD			0x8080
  ------------------
  178|   160k|			ctx, ctx->debug_file,
  179|   160k|			"%s",
  180|   160k|			ctx->app_name);
  181|   160k|	sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|   160k|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  182|   160k|			ctx, ctx->debug_file,
  183|   160k|			"] ");
  184|       |
  185|   160k|	if (file != NULL) {
  ------------------
  |  Branch (185:6): [True: 160k, False: 0]
  ------------------
  186|   160k|		sc_color_fprintf(SC_COLOR_FG_YELLOW,
  ------------------
  |  |   46|   160k|#define SC_COLOR_FG_YELLOW		0x0004
  ------------------
  187|   160k|				ctx, ctx->debug_file,
  188|   160k|				"%s:%d:%s: ",
  189|   160k|				file, line, func ? func : "");
  ------------------
  |  Branch (189:17): [True: 160k, False: 0]
  ------------------
  190|   160k|	}
  191|       |
  192|   160k|	sc_color_fprintf_va(color, ctx, ctx->debug_file, format, args);
  193|   160k|	if (strlen(format) == 0 || format[strlen(format) - 1] != '\n')
  ------------------
  |  Branch (193:6): [True: 0, False: 160k]
  |  Branch (193:29): [True: 65.2k, False: 95.5k]
  ------------------
  194|  65.2k|		sc_color_fprintf(color, ctx, ctx->debug_file, "\n");
  195|   160k|	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|   160k|}
log.c:sc_color_fprintf_va:
  266|  1.19M|{
  267|  1.19M|	int r;
  268|       |#ifdef _WIN32
  269|       |	WORD old_attr = 0;
  270|       |	int fd = stream ? fileno(stream) : -1;
  271|       |	HANDLE handle = fd >= 0 ? (HANDLE) _get_osfhandle(fd) : INVALID_HANDLE_VALUE;
  272|       |#endif
  273|       |
  274|  1.19M|	if (!is_a_tty(stream))
  ------------------
  |  Branch (274:6): [True: 1.19M, False: 0]
  ------------------
  275|  1.19M|		colors = 0;
  276|       |
  277|  1.19M|	if (colors && (!ctx || (!(ctx->flags & SC_CTX_FLAG_DISABLE_COLORS)))) {
  ------------------
  |  |  862|      0|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  |  Branch (277:6): [True: 0, False: 1.19M]
  |  Branch (277:17): [True: 0, False: 0]
  |  Branch (277:25): [True: 0, False: 0]
  ------------------
  278|       |#ifdef _WIN32
  279|       |		WORD attr = 0;
  280|       |		CONSOLE_SCREEN_BUFFER_INFO csbi;
  281|       |		GetConsoleScreenBufferInfo(handle, &csbi);
  282|       |		old_attr = csbi.wAttributes;
  283|       |#endif
  284|      0|		set_color(SC_COLOR_FG_RED,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  285|      0|				FOREGROUND_RED,
  286|      0|				"\x1b[31m");
  287|      0|		set_color(SC_COLOR_FG_GREEN,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  288|      0|				FOREGROUND_GREEN,
  289|      0|				"\x1b[32m");
  290|      0|		set_color(SC_COLOR_FG_YELLOW,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  291|      0|				FOREGROUND_GREEN|FOREGROUND_RED,
  292|      0|				"\x1b[33m");
  293|      0|		set_color(SC_COLOR_FG_BLUE,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  294|      0|				FOREGROUND_BLUE,
  295|      0|				"\x1b[34m");
  296|      0|		set_color(SC_COLOR_FG_MAGENTA,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  297|      0|				FOREGROUND_BLUE|FOREGROUND_RED,
  298|      0|				"\x1b[35m");
  299|      0|		set_color(SC_COLOR_FG_CYAN,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  300|      0|				FOREGROUND_BLUE|FOREGROUND_GREEN,
  301|      0|				"\x1b[36m");
  302|      0|		set_color(SC_COLOR_BG_RED,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  303|      0|				FOREGROUND_RED,
  304|      0|				"\x1b[41m");
  305|      0|		set_color(SC_COLOR_BG_GREEN,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  306|      0|				BACKGROUND_GREEN,
  307|      0|				"\x1b[42m");
  308|      0|		set_color(SC_COLOR_BG_YELLOW,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  309|      0|				BACKGROUND_GREEN|BACKGROUND_RED,
  310|      0|				"\x1b[43m");
  311|      0|		set_color(SC_COLOR_BG_BLUE,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  312|      0|				BACKGROUND_BLUE,
  313|      0|				"\x1b[44m");
  314|      0|		set_color(SC_COLOR_BG_MAGENTA,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  315|      0|				BACKGROUND_BLUE|BACKGROUND_RED,
  316|      0|				"\x1b[45m");
  317|      0|		set_color(SC_COLOR_BG_CYAN,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  318|      0|				BACKGROUND_BLUE|BACKGROUND_GREEN,
  319|      0|				"\x1b[46m");
  320|      0|		set_color(SC_COLOR_BOLD,
  ------------------
  |  |  250|      0|	do { if (colors & sc_color) { fprintf(stream, vt100_color); } } while (0)
  |  |  ------------------
  |  |  |  Branch (250:11): [True: 0, False: 0]
  |  |  |  Branch (250:73): [Folded, False: 0]
  |  |  ------------------
  ------------------
  321|      0|				FOREGROUND_INTENSITY,
  322|      0|				"\x1b[1m");
  323|       |#ifdef _WIN32
  324|       |		SetConsoleTextAttribute(handle, attr);
  325|       |#endif
  326|      0|	}
  327|       |
  328|  1.19M|	r = vfprintf(stream, format, args);
  329|       |
  330|  1.19M|	if (colors && (!ctx || (!(ctx->flags & SC_CTX_FLAG_DISABLE_COLORS)))) {
  ------------------
  |  |  862|      0|#define SC_CTX_FLAG_DISABLE_COLORS			0x00000020
  ------------------
  |  Branch (330:6): [True: 0, False: 1.19M]
  |  Branch (330:17): [True: 0, False: 0]
  |  Branch (330:25): [True: 0, False: 0]
  ------------------
  331|       |#ifdef _WIN32
  332|       |		SetConsoleTextAttribute(handle, old_attr);
  333|       |#else
  334|      0|		fprintf(stream, "\x1b[0m");
  335|      0|#endif
  336|      0|	}
  337|       |
  338|  1.19M|	return r;
  339|  1.19M|}
log.c:is_a_tty:
  228|  1.19M|{
  229|  1.19M|	if (fp != NULL) {
  ------------------
  |  Branch (229:6): [True: 1.19M, False: 0]
  ------------------
  230|  1.19M|		int fd = fileno(fp);
  231|  1.19M|		if (fd >= 0) {
  ------------------
  |  Branch (231:7): [True: 0, False: 1.19M]
  ------------------
  232|       |#ifdef _WIN32
  233|       |			HANDLE h = (HANDLE)_get_osfhandle(fd);
  234|       |			if (h != INVALID_HANDLE_VALUE) {
  235|       |				return GetFileType(h) == FILE_TYPE_CHAR;
  236|       |			}
  237|       |#else
  238|      0|			return isatty(fd);
  239|      0|#endif
  240|      0|		}
  241|  1.19M|	}
  242|  1.19M|	return 0;
  243|  1.19M|}

mscfs_new:
   45|    535|mscfs_t *mscfs_new(void) {
   46|    535|	mscfs_t *fs = malloc(sizeof(mscfs_t));
   47|    535|	if (!fs)
  ------------------
  |  Branch (47:6): [True: 0, False: 535]
  ------------------
   48|      0|		return NULL;
   49|    535|	memset(fs, 0, sizeof(mscfs_t));
   50|    535|	memcpy(fs->currentPath, "\x3F\x00", 2);
   51|    535|	return fs;
   52|    535|}
mscfs_free:
   54|    535|void mscfs_free(mscfs_t *fs) {
   55|    535|	mscfs_clear_cache(fs);
   56|    535|	free(fs);
   57|    535|}
mscfs_clear_cache:
   59|  1.72k|void mscfs_clear_cache(mscfs_t* fs) {
   60|  1.72k|	if(!fs->cache.array) {
  ------------------
  |  Branch (60:5): [True: 1.40k, False: 324]
  ------------------
   61|  1.40k|		return;
   62|  1.40k|	}
   63|    324|	free(fs->cache.array);
   64|       |	fs->cache.array = NULL;
   65|    324|	fs->cache.totalSize = 0;
   66|    324|	fs->cache.size = 0;
   67|    324|}
mscfs_push_file:
   83|  42.4k|{
   84|  42.4k|	mscfs_cache_t *cache = &fs->cache;
   85|  42.4k|	if (cache->size >= MAX_FILES)
  ------------------
  |  |   81|  42.4k|#define MAX_FILES 10000
  ------------------
  |  Branch (85:6): [True: 1, False: 42.4k]
  ------------------
   86|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
   87|  42.4k|	if(!cache->array || cache->size == cache->totalSize) {
  ------------------
  |  Branch (87:5): [True: 324, False: 42.1k]
  |  Branch (87:22): [True: 321, False: 41.8k]
  ------------------
   88|    645|		int length = cache->totalSize + MSCFS_CACHE_INCREMENT;
  ------------------
  |  |   35|    645|#define MSCFS_CACHE_INCREMENT 128
  ------------------
   89|    645|		mscfs_file_t *oldArray;
   90|    645|		cache->totalSize = length;
   91|    645|		oldArray = cache->array;
   92|    645|		cache->array = malloc(sizeof(mscfs_file_t) * length);
   93|    645|		if(!cache->array)
  ------------------
  |  Branch (93:6): [True: 0, False: 645]
  ------------------
   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|    645|		if(oldArray) {
  ------------------
  |  Branch (95:6): [True: 321, False: 324]
  ------------------
   96|    321|			memcpy(cache->array, oldArray, sizeof(mscfs_file_t) * cache->size);
   97|    321|			free(oldArray);
   98|    321|		}
   99|    645|	}
  100|  42.4k|	cache->array[cache->size] = *file;
  101|  42.4k|	cache->size++;
  102|  42.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  42.4k|#define SC_SUCCESS				0
  ------------------
  103|  42.4k|}
mscfs_update_cache:
  105|  1.19k|int mscfs_update_cache(mscfs_t* fs) {
  106|  1.19k|	mscfs_file_t file;
  107|  1.19k|	int r;
  108|  1.19k|	mscfs_clear_cache(fs);
  109|  1.19k|	r = fs->listFile(&file, 1, fs->udata);
  110|  1.19k|	if(r == 0)
  ------------------
  |  Branch (110:5): [True: 64, False: 1.12k]
  ------------------
  111|     64|		return 0;
  112|  1.12k|	else if(r < 0)
  ------------------
  |  Branch (112:10): [True: 768, False: 358]
  ------------------
  113|    768|		return r;
  114|  42.5k|	while(1) {
  ------------------
  |  Branch (114:8): [True: 42.5k, Folded]
  ------------------
  115|  42.5k|		if(!mscfs_is_ignored(fs, file.objectId)) {
  ------------------
  |  Branch (115:6): [True: 42.4k, False: 48]
  ------------------
  116|       |			/* Check if its a directory in the root */
  117|  42.4k|			u8* oid = file.objectId.id;
  118|  42.4k|			if(oid[2] == 0 && oid[3] == 0) {
  ------------------
  |  Branch (118:7): [True: 8.74k, False: 33.7k]
  |  Branch (118:22): [True: 3.53k, False: 5.20k]
  ------------------
  119|  3.53k|				oid[2] = oid[0];
  120|  3.53k|				oid[3] = oid[1];
  121|  3.53k|				oid[0] = 0x3F;
  122|  3.53k|				oid[1] = 0x00;
  123|  3.53k|				file.ef = 0;
  124|  38.9k|			} else  {
  125|  38.9k|				file.ef = 1; /* File is a working elementary file */
  126|  38.9k|			}
  127|       |
  128|  42.4k|			r = mscfs_push_file(fs, &file);
  129|  42.4k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  42.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (129:8): [True: 1, False: 42.4k]
  ------------------
  130|      1|				return r;
  131|  42.4k|		}
  132|  42.5k|		r = fs->listFile(&file, 0, fs->udata);
  133|  42.5k|		if(r == 0)
  ------------------
  |  Branch (133:6): [True: 179, False: 42.3k]
  ------------------
  134|    179|			break;
  135|  42.3k|		else if(r < 0)
  ------------------
  |  Branch (135:11): [True: 178, False: 42.1k]
  ------------------
  136|    178|			return r;
  137|  42.5k|	}
  138|    179|	return fs->cache.size;
  139|    358|}
mscfs_check_cache:
  142|  3.13k|{
  143|  3.13k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.13k|#define SC_SUCCESS				0
  ------------------
  144|  3.13k|	if(!fs->cache.array) {
  ------------------
  |  Branch (144:5): [True: 1.19k, False: 1.94k]
  ------------------
  145|  1.19k|		r = mscfs_update_cache(fs);
  146|  1.19k|	}
  147|  3.13k|	return r;
  148|  3.13k|}
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: 575, False: 828]
  ------------------
  154|    575|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|    575|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|    575|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  155|    828|	if(isDirectory) {
  ------------------
  |  Branch (155:5): [True: 0, False: 828]
  ------------------
  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|    828|	oid[0] = fs->currentPath[0];
  167|    828|	oid[1] = fs->currentPath[1];
  168|       |	/* Chop off the root in the path */
  169|    828|	if(pathlen > 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (169:5): [True: 780, False: 48]
  |  Branch (169:20): [True: 750, False: 30]
  ------------------
  170|    750|		path += 2;
  171|    750|		pathlen -= 2;
  172|    750|		oid[0] = 0x3F;
  173|    750|		oid[1] = 0x00;
  174|    750|	}
  175|       |	/* Limit to a single directory */
  176|    828|	if(pathlen > 4)
  ------------------
  |  Branch (176:5): [True: 21, False: 807]
  ------------------
  177|     21|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   33|     21|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|     21|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  178|       |	/* Reset to root */
  179|    807|	if(pathlen == 2 && 0 == memcmp(path, "\x3F\x00", 2)) {
  ------------------
  |  Branch (179:5): [True: 493, False: 314]
  |  Branch (179:21): [True: 1, False: 492]
  ------------------
  180|      1|		oid[0] = oid[2] = path[0];
  181|      1|		oid[1] = oid[3] = path[1];
  182|    806|	} else if(pathlen == 2) { /* Path preserved for current-path */
  ------------------
  |  Branch (182:12): [True: 492, False: 314]
  ------------------
  183|    492|		oid[2] = path[0];
  184|    492|		oid[3] = path[1];
  185|    492|	} else if(pathlen == 4) {
  ------------------
  |  Branch (185:12): [True: 313, False: 1]
  ------------------
  186|    313|		oid[0] = path[0];
  187|    313|		oid[1] = path[1];
  188|    313|		oid[2] = path[2];
  189|    313|		oid[3] = path[3];
  190|    313|	}
  191|       |
  192|    807|	return 0;
  193|    828|}
mscfs_check_selection:
  207|    308|{
  208|    308|	if(fs->currentPath[0] == 0 && fs->currentPath[1] == 0)
  ------------------
  |  Branch (208:5): [True: 0, False: 308]
  |  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|    308|	if(requiredItem == 1 && fs->currentFile[0] == 0 && fs->currentFile[1] == 0)
  ------------------
  |  Branch (210:5): [True: 0, False: 308]
  |  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|    308|	return 0;
  213|    308|}
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: 596, False: 807]
  ------------------
  223|    596|		return rc;
  224|    596|	}
  225|       |
  226|       |	/* Obtain file information while checking if it exists */
  227|    807|	rc = mscfs_check_cache(fs);
  228|    807|	if (rc < 0)
  ------------------
  |  Branch (228:6): [True: 27, False: 780]
  ------------------
  229|     27|		return rc;
  230|    780|	if(idx) *idx = -1;
  ------------------
  |  Branch (230:5): [True: 780, False: 0]
  ------------------
  231|  87.8k|	for(x = 0; x < fs->cache.size; x++) {
  ------------------
  |  Branch (231:13): [True: 87.3k, False: 481]
  ------------------
  232|  87.3k|		*file_data = &fs->cache.array[x];
  233|  87.3k|		if (*file_data) {
  ------------------
  |  Branch (233:7): [True: 87.3k, False: 0]
  ------------------
  234|  87.3k|			msc_id objectId;
  235|  87.3k|			objectId = (*file_data)->objectId;
  236|  87.3k|			if(0 == memcmp(objectId.id, fullPath.id, 4)) {
  ------------------
  |  Branch (236:7): [True: 299, False: 87.0k]
  ------------------
  237|    299|				if (idx)
  ------------------
  |  Branch (237:9): [True: 299, False: 0]
  ------------------
  238|    299|					*idx = x;
  239|    299|				break;
  240|    299|			}
  241|  87.0k|			*file_data = NULL;
  242|  87.0k|		}
  243|  87.3k|	}
  244|    780|	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: 481, False: 299]
  |  Branch (244:28): [True: 12, False: 469]
  |  Branch (244:79): [True: 228, False: 241]
  |  Branch (244:131): [True: 1, False: 240]
  ------------------
  245|    241|		static mscfs_file_t ROOT_FILE;
  246|    241|		ROOT_FILE.ef = 0;
  247|    241|		ROOT_FILE.size = 0;
  248|       |		/* Faked Root ID */
  249|    241|		ROOT_FILE.objectId = rootId;
  250|       |
  251|    241|		ROOT_FILE.read = 0;
  252|    241|		ROOT_FILE.write = 0x02; /* User Pin access */
  253|    241|		ROOT_FILE.delete = 0x02;
  254|       |
  255|    241|		*file_data = &ROOT_FILE;
  256|    241|		if(idx) *idx = -2;
  ------------------
  |  Branch (256:6): [True: 241, False: 0]
  ------------------
  257|    539|	} else if(*file_data == NULL) {
  ------------------
  |  Branch (257:12): [True: 240, False: 299]
  ------------------
  258|    240|		return MSCFS_FILE_NOT_FOUND;
  ------------------
  |  |   34|    240|#define MSCFS_FILE_NOT_FOUND 	SC_ERROR_FILE_NOT_FOUND
  |  |  ------------------
  |  |  |  |   51|    240|#define SC_ERROR_FILE_NOT_FOUND			-1201
  |  |  ------------------
  ------------------
  259|    240|	}
  260|       |
  261|    540|	return 0;
  262|    780|}
muscle-filesystem.c:mscfs_is_ignored:
   70|  42.5k|{
   71|  42.5k|	int ignored = 0;
   72|  42.5k|	const u8** ptr = ignoredFiles;
   73|   127k|	while(ptr && *ptr && !ignored) {
  ------------------
  |  Branch (73:8): [True: 127k, False: 0]
  |  Branch (73:15): [True: 85.0k, False: 42.5k]
  |  Branch (73:23): [True: 85.0k, False: 2]
  ------------------
   74|  85.0k|		if(0 == memcmp(objectId.id, *ptr, 4))
  ------------------
  |  Branch (74:6): [True: 48, False: 85.0k]
  ------------------
   75|     48|			ignored = 1;
   76|  85.0k|		ptr++;
   77|  85.0k|	}
   78|  42.5k|	return ignored;
   79|  42.5k|}

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

sc_pkcs1_strip_02_padding_constant_time:
  154|     73|{
  155|     73|	unsigned int i = 0;
  156|     73|	u8 *msg, *msg_orig = NULL;
  157|     73|	unsigned int good, found_zero_byte, mask, tmp_outlen;
  158|     73|	unsigned int zero_index = 0, msg_index, mlen = -1, len = 0;
  159|     73|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|       |
  161|     73|	if (data == NULL || data_len <= 0 || data_len > n ||
  ------------------
  |  Branch (161:6): [True: 0, False: 73]
  |  Branch (161:22): [True: 4, False: 69]
  |  Branch (161:39): [True: 32, False: 37]
  ------------------
  162|     37|			n < SC_PKCS1_PADDING_MIN_SIZE || out_len == NULL)
  ------------------
  |  |   40|    110|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (162:4): [True: 0, False: 37]
  |  Branch (162:37): [True: 0, False: 37]
  ------------------
  163|     73|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|       |
  165|     37|	tmp_outlen = *out_len;
  166|     37|	msg = msg_orig = calloc(n, sizeof(u8));
  167|     37|	if (msg == NULL)
  ------------------
  |  Branch (167:6): [True: 0, False: 37]
  ------------------
  168|     37|		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|     37|	len = data_len;
  177|  8.99k|	for (data += len, msg += n, i = 0; i < n; i++) {
  ------------------
  |  Branch (177:37): [True: 8.96k, False: 37]
  ------------------
  178|  8.96k|		mask = ~constant_time_is_zero(len);
  179|  8.96k|		len -= 1 & mask;
  180|  8.96k|		data -= 1 & mask;
  181|  8.96k|		*--msg = *data & mask;
  182|  8.96k|	}
  183|       |	// check first byte to be 0x00
  184|     37|	good = constant_time_is_zero(msg[0]);
  185|       |	// check second byte to be 0x02
  186|     37|	good &= constant_time_eq(msg[1], 2);
  187|       |
  188|       |	// find zero byte after random data in padding
  189|     37|	found_zero_byte = 0;
  190|  8.92k|	for (i = 2; i < n; i++) {
  ------------------
  |  Branch (190:14): [True: 8.88k, False: 37]
  ------------------
  191|  8.88k|		unsigned int equals0 = constant_time_is_zero(msg[i]);
  192|  8.88k|		zero_index = constant_time_select(~found_zero_byte & equals0, i, zero_index);
  193|  8.88k|		found_zero_byte |= equals0;
  194|  8.88k|	}
  195|       |
  196|       |	// zero_index stands for index of last found zero
  197|     37|	good &= constant_time_ge(zero_index, 2 + 8);
  198|       |
  199|       |	// start of the actual message in data
  200|     37|	msg_index = zero_index + 1;
  201|       |
  202|       |	// length of message
  203|     37|	mlen = data_len - msg_index;
  204|       |
  205|       |	// check that message fits into out buffer
  206|     37|	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|     37|	tmp_outlen = constant_time_select(constant_time_lt(n - SC_PKCS1_PADDING_MIN_SIZE, tmp_outlen),
  ------------------
  |  |   40|     37|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  210|     37|			n - SC_PKCS1_PADDING_MIN_SIZE, tmp_outlen);
  ------------------
  |  |   40|     37|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  211|    329|	for (msg_index = 1; msg_index < n - SC_PKCS1_PADDING_MIN_SIZE; msg_index <<= 1) {
  ------------------
  |  |   40|    329|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (211:22): [True: 292, False: 37]
  ------------------
  212|    292|		mask = ~constant_time_eq(msg_index & (n - SC_PKCS1_PADDING_MIN_SIZE - mlen), 0);
  ------------------
  |  |   40|    292|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  213|  59.3k|		for (i = SC_PKCS1_PADDING_MIN_SIZE; i < n - msg_index; i++)
  ------------------
  |  |   40|    292|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (213:39): [True: 59.0k, False: 292]
  ------------------
  214|  59.0k|			msg[i] = constant_time_select_8(mask, msg[i + msg_index], msg[i]);
  215|    292|	}
  216|       |	// move message into out buffer, if good
  217|  2.21k|	for (i = 0; i < tmp_outlen; i++) {
  ------------------
  |  Branch (217:14): [True: 2.17k, False: 37]
  ------------------
  218|  2.17k|		unsigned int msg_index;
  219|       |		// when out is longer than message in data, use some bogus index in msg
  220|  2.17k|		mask = good & constant_time_lt(i, mlen);
  221|  2.17k|		msg_index = constant_time_select(mask, i + SC_PKCS1_PADDING_MIN_SIZE, 0); // to now overflow msg buffer
  ------------------
  |  |   40|  2.17k|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  222|  2.17k|		out[i] = constant_time_select_8(mask, msg[msg_index], out[i]);
  223|  2.17k|	}
  224|       |
  225|     37|	*out_len = constant_time_select(good, mlen, *out_len);
  226|     37|	free(msg_orig);
  227|     37|	return constant_time_select(good, mlen, SC_ERROR_WRONG_PADDING);
  ------------------
  |  |   93|     37|#define SC_ERROR_WRONG_PADDING			-1412
  ------------------
  228|     37|}
sc_pkcs1_encode:
  612|     88|{
  613|     88|	int    rv, i;
  614|     88|	size_t tmp_len = *out_len;
  615|     88|	const u8    *tmp = in;
  616|     88|	unsigned int hash_algo, pad_algo;
  617|     88|	size_t mod_len = BYTES4BITS(mod_bits);
  ------------------
  |  |  146|     88|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  618|     88|#ifdef ENABLE_OPENSSL
  619|     88|	size_t sLen;
  620|     88|	EVP_MD* md = NULL;
  621|     88|	unsigned int mgf1_hash;
  622|     88|#endif
  623|       |
  624|     88|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     88|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     88|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     88|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     88|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  625|       |
  626|     88|	hash_algo = flags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|     88|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  627|     88|	pad_algo  = flags & SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|     88|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  628|     88|	if (pad_algo == 0)
  ------------------
  |  Branch (628:6): [True: 47, False: 41]
  ------------------
  629|     47|		pad_algo = SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|     47|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  630|     88|	sc_log(ctx, "hash algorithm 0x%X, pad algorithm 0x%X", hash_algo, pad_algo);
  ------------------
  |  |   71|     88|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  631|       |
  632|     88|	if ((pad_algo == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 || pad_algo == SC_ALGORITHM_RSA_PAD_NONE) &&
  ------------------
  |  |  109|    176|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              	if ((pad_algo == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 || pad_algo == SC_ALGORITHM_RSA_PAD_NONE) &&
  ------------------
  |  |  104|     47|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (632:7): [True: 41, False: 47]
  |  Branch (632:57): [True: 47, False: 0]
  ------------------
  633|     88|	    hash_algo != SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|     88|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (633:6): [True: 88, False: 0]
  ------------------
  634|     88|		i = sc_pkcs1_add_digest_info_prefix(hash_algo, in, in_len, out, &tmp_len);
  635|     88|		if (i != SC_SUCCESS) {
  ------------------
  |  |   28|     88|#define SC_SUCCESS				0
  ------------------
  |  Branch (635:7): [True: 17, False: 71]
  ------------------
  636|     17|			sc_log(ctx, "Unable to add digest info 0x%x", hash_algo);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  637|     17|			LOG_FUNC_RETURN(ctx, i);
  ------------------
  |  |  164|     17|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     17|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     17|	int _ret = r; \
  |  |  |  |  155|     17|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     17|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     17|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     17|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     17|	return _ret; \
  |  |  |  |  163|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|     17|		}
  639|     71|		tmp = out;
  640|     71|	} else   {
  641|      0|		tmp_len = in_len;
  642|      0|	}
  643|       |
  644|     71|	switch(pad_algo) {
  645|     32|	case SC_ALGORITHM_RSA_PAD_NONE:
  ------------------
  |  |  104|     32|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (645:2): [True: 32, False: 39]
  ------------------
  646|       |		/* padding done by card => nothing to do */
  647|     32|		if (out != tmp)
  ------------------
  |  Branch (647:7): [True: 0, False: 32]
  ------------------
  648|      0|			memcpy(out, tmp, tmp_len);
  649|     32|		*out_len = tmp_len;
  650|     32|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     32|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     32|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     32|	int _ret = r; \
  |  |  |  |  155|     32|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  157|     32|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  651|     39|	case SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01:
  ------------------
  |  |  109|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (651:2): [True: 39, False: 32]
  ------------------
  652|       |		/* add pkcs1 bt01 padding */
  653|     39|		rv = sc_pkcs1_add_01_padding(tmp, tmp_len, out, out_len, mod_len);
  654|     39|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     39|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     39|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     39|	int _ret = r; \
  |  |  |  |  155|     39|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 39]
  |  |  |  |  ------------------
  |  |  |  |  157|     39|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     39|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     39|	return _ret; \
  |  |  |  |  163|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  655|      0|	case SC_ALGORITHM_RSA_PAD_PSS:
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (655:2): [True: 0, False: 71]
  ------------------
  656|       |		/* add PSS padding */
  657|      0|#ifdef ENABLE_OPENSSL
  658|      0|		mgf1_hash = flags & SC_ALGORITHM_MGF1_HASHES;
  ------------------
  |  |  150|      0|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
  659|      0|		if (hash_algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (659:7): [True: 0, False: 0]
  ------------------
  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|      0|		if (!(md = hash_flag2md(ctx, hash_algo))) {
  ------------------
  |  Branch (669:7): [True: 0, False: 0]
  ------------------
  670|      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__
  |  |  ------------------
  ------------------
  671|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  672|      0|		}
  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: 71]
  ------------------
  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|     71|	}
  695|     71|}
sc_get_encoding_flags:
  700|    464|{
  701|    464|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    464|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    464|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    464|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    464|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 464]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  702|    464|	if (pflags == NULL || sflags == NULL)
  ------------------
  |  Branch (702:6): [True: 0, False: 464]
  |  Branch (702:24): [True: 0, False: 464]
  ------------------
  703|    464|		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|    464|	sc_log(ctx, "iFlags 0x%lX, card capabilities 0x%lX", iflags, caps);
  ------------------
  |  |   71|    464|#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|    464|	if ((caps & iflags) == iflags) {
  ------------------
  |  Branch (716:6): [True: 193, False: 271]
  ------------------
  717|       |		/* Card supports the signature operation we want to do, great, let's
  718|       |		 * go with it then. */
  719|    193|		*sflags = iflags;
  720|    193|		*pflags = 0;
  721|       |
  722|    271|	} else if ((caps & SC_ALGORITHM_RSA_PAD_PSS) &&
  ------------------
  |  |  107|    271|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (722:13): [True: 0, False: 271]
  ------------------
  723|      0|			(iflags & SC_ALGORITHM_RSA_PAD_PSS)) {
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (723:4): [True: 0, False: 0]
  ------------------
  724|      0|		*sflags |= SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  725|      0|		*sflags |= iflags & SC_ALGORITHM_MGF1_HASHES;
  ------------------
  |  |  150|      0|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
  726|      0|		*pflags = iflags & ~(iflags & (SC_ALGORITHM_MGF1_HASHES | SC_ALGORITHM_RSA_PAD_PSS));
  ------------------
  |  |  150|      0|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
              		*pflags = iflags & ~(iflags & (SC_ALGORITHM_MGF1_HASHES | SC_ALGORITHM_RSA_PAD_PSS));
  ------------------
  |  |  107|      0|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  727|       |
  728|    271|	} else if ((caps & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  102|    271|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (728:13): [True: 175, False: 96]
  ------------------
  729|    175|				(iflags & SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    350|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    175|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    175|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (729:6): [True: 171, False: 4]
  ------------------
  730|      4|				|| iflags & SC_ALGORITHM_RSA_PAD_PSS
  ------------------
  |  |  107|    179|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (730:8): [True: 0, False: 4]
  ------------------
  731|      4|#ifdef ENABLE_OPENSSL
  732|      4|				|| iflags & SC_ALGORITHM_RSA_PAD_OAEP
  ------------------
  |  |  108|    179|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (732:8): [True: 0, False: 4]
  ------------------
  733|      4|#endif
  734|    171|				|| iflags & SC_ALGORITHM_RSA_PAD_NONE)) {
  ------------------
  |  |  104|      4|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (734:8): [True: 0, False: 4]
  ------------------
  735|       |		/* Use the card's raw RSA capability on the padded input */
  736|    171|		*sflags = SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|    171|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  737|    171|		*pflags = iflags;
  738|       |
  739|    171|	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  109|    100|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  133|    100|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (739:13): [True: 97, False: 3]
  ------------------
  740|     97|			(iflags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)) {
  ------------------
  |  |  109|     97|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (740:4): [True: 44, False: 53]
  ------------------
  741|       |		/* A corner case - the card can partially do PKCS1, if we prepend the
  742|       |		 * DigestInfo bit it will do the rest. */
  743|     44|		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  109|     44|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     44|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  744|     44|		*pflags = iflags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|     44|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  745|       |
  746|     56|	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  110|     56|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
              	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  133|     56|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (746:13): [True: 53, False: 3]
  ------------------
  747|     53|			(iflags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)) {
  ------------------
  |  |  110|     53|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (747:4): [True: 49, False: 4]
  ------------------
  748|     49|		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  110|     49|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
              		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|     49|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  749|     49|		*pflags = iflags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|     49|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  750|       |
  751|     49|	} else if ((iflags & SC_ALGORITHM_AES) == SC_ALGORITHM_AES) { /* TODO: seems like this constant does not belong to the same set of flags used form asymmetric algos. Fix this! */
  ------------------
  |  |   79|      7|#define SC_ALGORITHM_AES		67
  ------------------
              	} else if ((iflags & SC_ALGORITHM_AES) == SC_ALGORITHM_AES) { /* TODO: seems like this constant does not belong to the same set of flags used form asymmetric algos. Fix this! */
  ------------------
  |  |   79|      7|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (751:13): [True: 0, False: 7]
  ------------------
  752|      0|		*sflags = 0;
  753|      0|		*pflags = 0;
  754|       |
  755|      7|	} else if ((iflags & SC_ALGORITHM_AES_FLAGS) > 0) {
  ------------------
  |  |  209|      7|#define SC_ALGORITHM_AES_FLAGS		 0x0F000000
  ------------------
  |  Branch (755:13): [True: 0, False: 7]
  ------------------
  756|      0|		*sflags = iflags & SC_ALGORITHM_AES_FLAGS;
  ------------------
  |  |  209|      0|#define SC_ALGORITHM_AES_FLAGS		 0x0F000000
  ------------------
  757|      0|		if (iflags & SC_ALGORITHM_AES_CBC_PAD)
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  |  Branch (757:7): [True: 0, False: 0]
  ------------------
  758|      0|			*pflags = SC_ALGORITHM_AES_CBC_PAD;
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  759|      0|		else
  760|      0|			*pflags = 0;
  761|       |
  762|      7|	} else {
  763|      7|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported algorithm");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  764|      7|	}
  765|       |
  766|    457|	sc_log(ctx, "pad flags 0x%lX, secure algorithm flags 0x%lX", *pflags, *sflags);
  ------------------
  |  |   71|    457|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  767|    457|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    457|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    457|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    457|	int _ret = r; \
  |  |  |  |  155|    457|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 457, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    457|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 457]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  768|    457|}
padding.c:sc_pkcs1_add_digest_info_prefix:
  381|     88|{
  382|     88|	int i;
  383|       |
  384|    234|	for (i = 0; digest_info_prefix[i].algorithm != 0; i++) {
  ------------------
  |  Branch (384:14): [True: 234, False: 0]
  ------------------
  385|    234|		if (algorithm == digest_info_prefix[i].algorithm) {
  ------------------
  |  Branch (385:7): [True: 88, False: 146]
  ------------------
  386|     88|			const u8 *hdr      = digest_info_prefix[i].hdr;
  387|     88|			size_t    hdr_len  = digest_info_prefix[i].hdr_len,
  388|     88|			          hash_len = digest_info_prefix[i].hash_len;
  389|       |
  390|     88|			if (in_len != hash_len || *out_len < (hdr_len + hash_len))
  ------------------
  |  Branch (390:8): [True: 13, False: 75]
  |  Branch (390:30): [True: 4, False: 71]
  ------------------
  391|     17|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     17|#define SC_ERROR_INTERNAL			-1400
  ------------------
  392|       |
  393|     71|			memmove(out + hdr_len, in, hash_len);
  394|     71|			memmove(out, hdr, hdr_len);
  395|     71|			*out_len = hdr_len + hash_len;
  396|       |
  397|     71|			return SC_SUCCESS;
  ------------------
  |  |   28|     71|#define SC_SUCCESS				0
  ------------------
  398|     88|		}
  399|    234|	}
  400|       |
  401|      0|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  402|     88|}
padding.c:sc_pkcs1_add_01_padding:
   97|     39|{
   98|     39|	size_t i;
   99|       |
  100|     39|	if (*out_len < mod_length)
  ------------------
  |  Branch (100:6): [True: 0, False: 39]
  ------------------
  101|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  102|     39|	if (in_len + 11 > mod_length)
  ------------------
  |  Branch (102:6): [True: 0, False: 39]
  ------------------
  103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  104|     39|	i = mod_length - in_len;
  105|     39|	memmove(out + i, in, in_len);
  106|     39|	*out++ = 0x00;
  107|     39|	*out++ = 0x01;
  108|       |
  109|     39|	memset(out, 0xFF, i - 3);
  110|     39|	out += i - 3;
  111|     39|	*out = 0x00;
  112|       |
  113|     39|	*out_len = mod_length;
  114|     39|	return SC_SUCCESS;
  ------------------
  |  |   28|     39|#define SC_SUCCESS				0
  ------------------
  115|     39|}

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

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

sc_pkcs15_read_cached_file:
  113|  6.22k|{
  114|  6.22k|	char fname[PATH_MAX];
  115|  6.22k|	int rv;
  116|  6.22k|	FILE *f;
  117|  6.22k|	size_t count;
  118|  6.22k|	struct stat stbuf;
  119|  6.22k|	u8 *data = NULL;
  120|       |
  121|  6.22k|	if (path->len < 2)
  ------------------
  |  Branch (121:6): [True: 2.02k, False: 4.20k]
  ------------------
  122|  2.02k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  2.02k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  123|       |
  124|       |	/* Accept full path or FILE-ID path with AID */
  125|  4.20k|	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  119|  4.20k|#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|  5.70k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (125:6): [True: 2.85k, False: 1.35k]
  |  Branch (125:44): [True: 0, False: 2.85k]
  |  Branch (125:82): [True: 1.72k, False: 1.12k]
  ------------------
  126|  1.72k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.72k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  127|       |
  128|  2.48k|	sc_log(p15card->card->ctx, "try to read cache for %s", sc_print_path(path));
  ------------------
  |  |   71|  2.48k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  129|  2.48k|	rv = generate_cache_filename(p15card, path, fname, sizeof(fname));
  130|  2.48k|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|  2.48k|#define SC_SUCCESS				0
  ------------------
  |  Branch (130:6): [True: 1.09k, False: 1.38k]
  ------------------
  131|  1.09k|		return rv;
  132|  1.38k|	sc_log(p15card->card->ctx, "read cached file %s", fname);
  ------------------
  |  |   71|  1.38k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  133|       |
  134|  1.38k|	f = fopen(fname, "rb");
  135|  1.38k|	if (!f)
  ------------------
  |  Branch (135:6): [True: 982, False: 404]
  ------------------
  136|    982|		return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    982|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  137|    404|	if (fstat(fileno(f), &stbuf))   {
  ------------------
  |  Branch (137:6): [True: 0, False: 404]
  ------------------
  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|    404|	if (path->count < 0) {
  ------------------
  |  Branch (142:6): [True: 89, False: 315]
  ------------------
  143|     89|		count = stbuf.st_size;
  144|     89|	}
  145|    315|	else {
  146|    315|		count = path->count;
  147|    315|		if (path->index + count > (size_t)stbuf.st_size)   {
  ------------------
  |  Branch (147:7): [True: 182, False: 133]
  ------------------
  148|    182|			rv = SC_ERROR_FILE_NOT_FOUND; /* cache file bad? */
  ------------------
  |  |   51|    182|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  149|    182|			goto err;
  150|    182|		}
  151|       |
  152|    133|		if (0 != fseek(f, (long)path->index, SEEK_SET)) {
  ------------------
  |  Branch (152:7): [True: 0, False: 133]
  ------------------
  153|      0|			rv = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  154|      0|			goto err;
  155|      0|		}
  156|    133|	}
  157|       |
  158|    222|	if (*buf == NULL) {
  ------------------
  |  Branch (158:6): [True: 219, False: 3]
  ------------------
  159|    219|		data = malloc((size_t)stbuf.st_size);
  160|    219|		if (data == NULL)   {
  ------------------
  |  Branch (160:7): [True: 0, False: 219]
  ------------------
  161|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  162|      0|			goto err;
  163|      0|		}
  164|    219|	}
  165|      3|	else {
  166|      3|		if (count > *bufsize) {
  ------------------
  |  Branch (166:7): [True: 1, False: 2]
  ------------------
  167|      1|			rv =  SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      1|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  168|      1|			goto err;
  169|      1|		}
  170|      2|		data = *buf;
  171|      2|	}
  172|       |
  173|    221|	if (count != fread(data, 1, count, f)) {
  ------------------
  |  Branch (173:6): [True: 0, False: 221]
  ------------------
  174|      0|		rv = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  175|      0|		goto err;
  176|      0|	}
  177|    221|	*buf = data;
  178|    221|	*bufsize = count;
  179|       |
  180|    221|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    221|#define SC_SUCCESS				0
  ------------------
  181|       |
  182|    404|err:
  183|    404|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    404|#define SC_SUCCESS				0
  ------------------
  |  Branch (183:6): [True: 183, False: 221]
  ------------------
  184|    183|		if (data != *buf) {
  ------------------
  |  Branch (184:7): [True: 1, False: 182]
  ------------------
  185|      1|			free(data);
  186|      1|		}
  187|    183|	}
  188|       |
  189|    404|	fclose(f);
  190|    404|	return rv;
  191|    221|}
sc_pkcs15_cache_file:
  196|  1.05k|{
  197|  1.05k|	char fname[PATH_MAX];
  198|  1.05k|	int r;
  199|  1.05k|	long len;
  200|  1.05k|	FILE *f;
  201|  1.05k|	size_t c;
  202|       |
  203|  1.05k|	r = generate_cache_filename(p15card, path, fname, sizeof(fname));
  204|  1.05k|	if (r != 0)
  ------------------
  |  Branch (204:6): [True: 781, False: 270]
  ------------------
  205|    781|		return r;
  206|       |
  207|    270|	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|    270|	if (f == NULL && errno == ENOENT) {
  ------------------
  |  Branch (211:6): [True: 74, False: 196]
  |  Branch (211:19): [True: 74, False: 0]
  ------------------
  212|     74|		if ((r = sc_make_cache_dir(p15card->card->ctx)) < 0)
  ------------------
  |  Branch (212:7): [True: 71, False: 3]
  ------------------
  213|     71|			return r;
  214|      3|		f = fopen(fname, "ab");
  215|      3|	}
  216|    199|	if (f == NULL)
  ------------------
  |  Branch (216:6): [True: 1, False: 198]
  ------------------
  217|      1|		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|    198|	len = ftell(f);
  222|    198|	if (len > path->index) {
  ------------------
  |  Branch (222:6): [True: 8, False: 190]
  ------------------
  223|       |		/* override previous cache records on this location */
  224|      8|		r = fseek(f, path->index, SEEK_SET);
  225|      8|		if (r != 0) {
  ------------------
  |  Branch (225:7): [True: 0, False: 8]
  ------------------
  226|      0|			fclose(f);
  227|      0|			return 0;
  228|      0|		}
  229|    190|	} else if (path->index > len) {
  ------------------
  |  Branch (229:13): [True: 5, False: 185]
  ------------------
  230|       |		/* We miss some bytes so we will not cache this chunk */
  231|      5|		fclose(f);
  232|      5|		return 0;
  233|      5|	}
  234|       |
  235|    193|	c = fwrite(buf, 1, bufsize, f);
  236|    193|	fclose(f);
  237|    193|	if (c != bufsize) {
  ------------------
  |  Branch (237:6): [True: 0, False: 193]
  ------------------
  238|      0|		sc_log(p15card->card->ctx, "fwrite() wrote only %zu bytes", c);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  239|      0|		unlink(fname);
  240|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  241|      0|	}
  242|    193|	return 0;
  243|    193|}
pkcs15-cache.c:generate_cache_filename:
   44|  3.53k|{
   45|  3.53k|	char dir[PATH_MAX];
   46|  3.53k|	char *last_update = NULL;
   47|  3.53k|	int  r;
   48|  3.53k|	unsigned u;
   49|  3.53k|	size_t change_counter;
   50|       |
   51|  3.53k|	if (p15card->tokeninfo->serial_number == NULL
  ------------------
  |  Branch (51:6): [True: 1.54k, False: 1.99k]
  ------------------
   52|  1.54k|			&& (p15card->card->uid.len == 0
  ------------------
  |  Branch (52:8): [True: 1.54k, False: 0]
  ------------------
   53|      0|				|| p15card->card->uid.value[0] == RANDOM_UID_INDICATOR))
  ------------------
  |  |   40|      0|#define RANDOM_UID_INDICATOR 0x08
  ------------------
  |  Branch (53:8): [True: 0, False: 0]
  ------------------
   54|  1.54k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.54k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   55|       |
   56|  1.99k|	if (path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  1.99k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (56:6): [True: 0, False: 1.99k]
  ------------------
   57|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   58|  1.99k|	r = sc_get_cache_dir(p15card->card->ctx, dir, sizeof(dir));
   59|  1.99k|	if (r)
  ------------------
  |  Branch (59:6): [True: 0, False: 1.99k]
  ------------------
   60|      0|		return r;
   61|  1.99k|	snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "/");
   62|       |
   63|  1.99k|	last_update = sc_pkcs15_get_lastupdate(p15card);
   64|  1.99k|	if (!last_update)
  ------------------
  |  Branch (64:6): [True: 1.99k, False: 0]
  ------------------
   65|  1.99k|		last_update = "NODATE";
   66|       |
   67|  1.99k|	if (p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (67:6): [True: 1.99k, False: 0]
  ------------------
   68|  1.99k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   69|  1.99k|				"%s_%s", p15card->tokeninfo->serial_number,
   70|  1.99k|				last_update);
   71|  1.99k|	} 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|  1.99k|	if (SC_SUCCESS == sc_card_ctl(p15card->card, SC_CARDCTL_GET_CHANGE_COUNTER, &change_counter))
  ------------------
  |  |   28|  1.99k|#define SC_SUCCESS				0
  ------------------
  |  Branch (78:6): [True: 1, False: 1.99k]
  ------------------
   79|      1|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_%zu", change_counter);
   80|       |
   81|  1.99k|	if (path->aid.len &&
  ------------------
  |  Branch (81:6): [True: 1.56k, False: 428]
  ------------------
   82|  1.56k|		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  117|  3.12k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
              		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  119|    311|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (82:4): [True: 1.25k, False: 311]
  |  Branch (82:42): [True: 5, False: 306]
  ------------------
   83|  1.25k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
   84|  10.0k|		for (u = 0; u < path->aid.len; u++)
  ------------------
  |  Branch (84:15): [True: 8.81k, False: 1.25k]
  ------------------
   85|  8.81k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   86|  8.81k|					"%02X",  path->aid.value[u]);
   87|  1.25k|	}
   88|    734|	else if (path->type != SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|    734|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (88:11): [True: 336, False: 398]
  ------------------
   89|    336|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    336|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   90|    336|	}
   91|       |
   92|  1.65k|	if (path->len)   {
  ------------------
  |  Branch (92:6): [True: 1.65k, False: 0]
  ------------------
   93|  1.65k|		size_t offs = 0;
   94|       |
   95|  1.65k|		if (path->len > 2 && memcmp(path->value, "\x3F\x00", 2) == 0)
  ------------------
  |  Branch (95:7): [True: 398, False: 1.25k]
  |  Branch (95:24): [True: 398, False: 0]
  ------------------
   96|    398|			offs = 2;
   97|  1.65k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
   98|  5.77k|		for (u = 0; u < path->len - offs; u++)
  ------------------
  |  Branch (98:15): [True: 4.11k, False: 1.65k]
  ------------------
   99|  4.11k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
  100|  4.11k|					"%02X",  path->value[u + offs]);
  101|  1.65k|	}
  102|       |
  103|  1.65k|	if (!buf)
  ------------------
  |  Branch (103:6): [True: 0, False: 1.65k]
  ------------------
  104|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  105|  1.65k|	strlcpy(buf, dir, bufsize);
  ------------------
  |  |   43|  1.65k|#define strlcpy _strlcpy
  ------------------
  106|       |
  107|  1.65k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.65k|#define SC_SUCCESS				0
  ------------------
  108|  1.65k|}

sc_pkcs15emu_cardos_init_ex:
  172|  6.95k|{
  173|  6.95k|	if (cardos_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (173:6): [True: 6.59k, False: 359]
  ------------------
  174|  6.59k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.59k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  175|       |
  176|    359|	return sc_pkcs15emu_cardos_init(p15card, aid);
  177|  6.95k|}
pkcs15-cardos.c:cardos_pkcs15emu_detect_card:
  138|  6.95k|{
  139|  6.95k|	if (p15card->card->type <  SC_CARD_TYPE_CARDOS_BASE)
  ------------------
  |  Branch (139:6): [True: 261, False: 6.69k]
  ------------------
  140|    261|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    261|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  141|       |
  142|  6.69k|	if (p15card->card->type >= SC_CARD_TYPE_CARDOS_BASE + 1000)
  ------------------
  |  Branch (142:6): [True: 6.33k, False: 359]
  ------------------
  143|  6.33k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.33k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  144|       |
  145|    359|	return SC_SUCCESS;
  ------------------
  |  |   28|    359|#define SC_SUCCESS				0
  ------------------
  146|  6.69k|}
pkcs15-cardos.c:sc_pkcs15emu_cardos_init:
  151|    359|{
  152|    359|	sc_card_t *card = p15card->card;
  153|    359|	int r;
  154|       |
  155|    359|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    359|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    359|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    359|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    359|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 359]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  156|       |
  157|    359|	r = sc_pkcs15_bind_internal(p15card, aid);
  158|    359|	LOG_TEST_RET(card->ctx, r, "sc_pkcs15_bind_internal failed");
  ------------------
  |  |  174|    359|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    359|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    359|	int _ret = (r); \
  |  |  |  |  168|    359|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 349, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|    349|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    349|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    349|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    349|		return _ret; \
  |  |  |  |  172|    349|	} \
  |  |  |  |  173|    359|} 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: 5, False: 5]
  |  Branch (162:27): [True: 5, False: 0]
  ------------------
  163|      5|		r = cardos_fix_token_info(p15card);
  164|      5|	}
  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|      5|{
   44|      5|	sc_card_t *card;
   45|      5|	struct sc_supported_algo_info (*saa)[SC_MAX_SUPPORTED_ALGORITHMS];
   46|      5|	struct sc_supported_algo_info *sa;
   47|      5|	struct sc_cardctl_cardos_pass_algo_flags *passed = NULL;
   48|      5|	int r = 0;
   49|      5|	int i;
   50|       |
   51|      5|	card = p15card->card;
   52|       |
   53|      5|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      5|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      5|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      5|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5]
  |  |  ------------------
  ------------------
   54|       |
   55|      5|	passed = calloc(1, sizeof(struct sc_cardctl_cardos_pass_algo_flags));
   56|      5|	if (!passed)
  ------------------
  |  Branch (56:6): [True: 0, False: 5]
  ------------------
   57|      5|		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|      5|	passed->pass = 1; /* get used_flags and card_flags from card */
   60|      5|	r = sc_card_ctl(p15card->card, SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS, passed);
   61|      5|	if (r < 0) {
  ------------------
  |  Branch (61:6): [True: 0, False: 5]
  ------------------
   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|      5|	saa = &(p15card->tokeninfo->supported_algos);
   67|       |
   68|      5|	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|      5|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   69|       |
   70|      5|	if (passed->card_flags) { /* user forced the flags, use them */
  ------------------
  |  Branch (70:6): [True: 0, False: 5]
  ------------------
   71|      0|		passed->new_flags = passed->card_flags; /* from card_atr flags */
   72|      5|	} else {
   73|       |
   74|      5|		for (i = 0, sa = saa[0]; i < SC_MAX_SUPPORTED_ALGORITHMS; i++, sa++) {
  ------------------
  |  |   61|      5|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (74:28): [True: 5, False: 0]
  ------------------
   75|       |
   76|      5|			if (sa->reference == 0 && sa->mechanism == 0
  ------------------
  |  Branch (76:8): [True: 5, False: 0]
  |  Branch (76:30): [True: 5, False: 0]
  ------------------
   77|      5|					&& sa->operations == 0 && sa->algo_ref == 0)
  ------------------
  |  Branch (77:9): [True: 5, False: 0]
  |  Branch (77:32): [True: 5, False: 0]
  ------------------
   78|      5|				break;
   79|       |
   80|      0|			sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "supported_algos[%d] mechanism:0x%8.8x", i, sa->mechanism);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   81|      0|			switch(sa->mechanism) {
   82|      0|			case 0x01 :
  ------------------
  |  Branch (82:4): [True: 0, False: 0]
  ------------------
   83|       |				/*
   84|       |				 * Card appears to use lower 4 bits of reference as key, and upper
   85|       |				 * 4 bits as mech for card.
   86|       |				 * Also has a bug if mechanism = 1 (CKM_RSA_PKCS1) and reference 0x10 
   87|       |				 * bit is set mechanism should be 3 (CKM_RSA_X_509) 
   88|       |				 * correct the mechanism in tokenInfo
   89|       |				 */
   90|      0|				if (sa->reference & 0x10) {
  ------------------
  |  Branch (90:9): [True: 0, False: 0]
  ------------------
   91|      0|					sc_log(card->ctx, "Changing mechanism to CKM_RSA_X_509 based on reference");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   92|      0|					passed->new_flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   93|      0|						| SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|      0|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
   94|      0|					sa->mechanism = 0x03;
   95|      0|				} else
   96|      0|				passed->new_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
   97|      0|				break;
   98|      0|			case 0x03 :
  ------------------
  |  Branch (98:4): [True: 0, False: 0]
  ------------------
   99|      0|				passed->new_flags |= SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  100|      0|					| SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|      0|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  101|      0|				break;
  102|      0|			case 0x06 :
  ------------------
  |  Branch (102:4): [True: 0, False: 0]
  ------------------
  103|      0|				passed->new_flags |= SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  104|      0|				break;
  105|      0|			case 0x1041:
  ------------------
  |  Branch (105:4): [True: 0, False: 0]
  ------------------
  106|      0|				passed->ec_flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  107|       |				/* no old_ec_flags */
  108|       |				/* TODO turn on sizes from  ec curves OIDS */
  109|      0|				break;
  110|      0|			default:
  ------------------
  |  Branch (110:4): [True: 0, False: 0]
  ------------------
  111|      0|				sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "UNKNOWN MECH: 0x%8.8x", sa->mechanism);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  112|      0|			}
  113|       |
  114|      0|			sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "New_flags 0x%8.8lx New_ec_flags: 0x%8.8lx",
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  115|      0|				passed->new_flags, passed->ec_flags);
  116|      0|		}
  117|       |
  118|      5|		if (passed->new_flags == 0) {
  ------------------
  |  Branch (118:7): [True: 5, False: 0]
  ------------------
  119|      5|			if (p15card->tokeninfo && p15card->tokeninfo->flags & SC_PKCS15_TOKEN_EID_COMPLIANT) {
  ------------------
  |  |  598|      5|#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
  ------------------
  |  Branch (119:8): [True: 5, False: 0]
  |  Branch (119:30): [True: 0, False: 5]
  ------------------
  120|      0|				sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "EID_COMPLIANT flag found");
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  121|      0|				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_FLAGS) | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |   96|      0|#define SC_ALGORITHM_SPECIFIC_FLAGS	0x001FFFFF
  ------------------
              				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_FLAGS) | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  122|      0|			} else
  123|      5|				passed->new_flags = passed->used_flags; /* from default cardos_init */
  124|      5|		}
  125|      5|	}
  126|       |
  127|      5|	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|      5|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  128|       |
  129|      5|	passed->pass = 2; /* tell card driver to use the new flags */
  130|      5|	r = sc_card_ctl(p15card->card, SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS, passed);
  131|       |
  132|      5|	free(passed);
  133|      5|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  134|      5|}

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

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

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

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

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

sc_pkcs15emu_dnie_init_ex:
  281|  8.64k|{
  282|  8.64k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  8.64k|#define SC_SUCCESS				0
  ------------------
  283|  8.64k|	sc_context_t *ctx = p15card->card->ctx;
  284|  8.64k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  8.64k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  8.64k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  8.64k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  8.64k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8.64k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|       |
  286|  8.64k|#if defined(ENABLE_OPENSSL) && defined(ENABLE_SM)
  287|       |	/* check for proper card */
  288|  8.64k|	r = dnie_match_card(p15card->card);
  289|  8.64k|	if (r == 0)
  ------------------
  |  Branch (289:6): [True: 8.05k, False: 586]
  ------------------
  290|  8.64k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  8.05k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.05k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.05k|	int _ret = r; \
  |  |  |  |  155|  8.05k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.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|  8.05k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.05k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.05k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  8.05k|	return _ret; \
  |  |  |  |  163|  8.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |	/* ok: initialize and return */
  292|    586|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_dnie_init(p15card));
  ------------------
  |  |  164|    586|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    586|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    586|	int _ret = r; \
  |  |  |  |  155|    586|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 586, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    586|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    548|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 548, False: 38]
  |  |  |  |  ------------------
  |  |  |  |  157|    586|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    586|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    586|	return _ret; \
  |  |  |  |  163|    586|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  293|       |#else
  294|       |	r = SC_ERROR_WRONG_CARD;
  295|       |	LOG_FUNC_RETURN(ctx, r);
  296|       |#endif
  297|    586|}
pkcs15-dnie.c:sc_pkcs15emu_dnie_init:
  139|    586|{
  140|    586|	u8 buf[1024];
  141|    586|	sc_pkcs15_df_t *df;
  142|    586|	sc_pkcs15_object_t *p15_obj;
  143|    586|	size_t len = sizeof(buf);
  144|    586|	int rv;
  145|    586|	struct sc_pkcs15_cert_info *p15_info = NULL;
  146|    586|	int use_pin_cache_backup = p15card->opts.use_pin_cache;
  147|       |
  148|    586|	sc_context_t *ctx = p15card->card->ctx;
  149|    586|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    586|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    586|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    586|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    586|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 586]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|       |
  151|       |	/* Check for correct card driver (i.e. iso7816) */
  152|    586|	if (strcmp(p15card->card->driver->short_name, "dnie") != 0)
  ------------------
  |  Branch (152:6): [True: 5, False: 581]
  ------------------
  153|      5|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      5|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  154|       |
  155|       |	/* Check for correct card atr */
  156|    581|	if (dnie_match_card(p15card->card) != 1)
  ------------------
  |  Branch (156:6): [True: 0, False: 581]
  ------------------
  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|    581|	if (p15card->card->atr.value[15] >= DNIE_30_VERSION) {
  ------------------
  |  |  100|    581|#define DNIE_30_VERSION 0x04
  ------------------
  |  Branch (162:6): [True: 387, False: 194]
  ------------------
  163|    387|		p15card->opts.use_pin_cache = 1;
  164|    387|		p15card->opts.pin_cache_counter = DNIE_30_CACHE_COUNTER;
  ------------------
  |  |  101|    387|#define DNIE_30_CACHE_COUNTER 30000
  ------------------
  165|    387|		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|    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__
  |  |  ------------------
  ------------------
  166|    387|			p15card->opts.use_file_cache,
  167|    387|			p15card->opts.use_pin_cache,
  168|    387|			p15card->opts.pin_cache_counter,
  169|    387|			p15card->opts.pin_cache_ignore_user_consent);
  170|    387|        }
  171|       |
  172|       |	/* Set root path of this application */
  173|    581|	sc_file_free(p15card->file_app);
  174|    581|	p15card->file_app = sc_file_new();
  175|    581|	if (NULL == p15card->file_app) {
  ------------------
  |  Branch (175:6): [True: 0, False: 581]
  ------------------
  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|    581|	sc_format_path("3F00", &p15card->file_app->path);
  180|       |
  181|       |	/* Load TokenInfo */
  182|    581|	rv = dump_ef(p15card->card, "3F0050155032", buf, &len);
  183|    581|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of EF.TOKENINFO failed.");
  ------------------
  |  |  184|    581|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    581|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    581|	int _ret = (r); \
  |  |  |  |  178|    581|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 434, False: 147]
  |  |  |  |  ------------------
  |  |  |  |  179|    434|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    434|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    434|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    434|		goto err; \
  |  |  |  |  182|    434|	} \
  |  |  |  |  183|    581|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 147]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|       |
  185|    147|	rv = sc_pkcs15_parse_tokeninfo(p15card->card->ctx, p15card->tokeninfo,
  186|    147|				       buf, len);
  187|    147|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of EF.TOKENINFO failed.");
  ------------------
  |  |  184|    147|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    147|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    147|	int _ret = (r); \
  |  |  |  |  178|    147|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 40, False: 107]
  |  |  |  |  ------------------
  |  |  |  |  179|     40|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     40|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     40|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     40|		goto err; \
  |  |  |  |  182|     40|	} \
  |  |  |  |  183|    147|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 107]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* Only accept the original stuff */
  190|    107|	if (strcmp(p15card->tokeninfo->manufacturer_id, "DGP-FNMT") != 0) {
  ------------------
  |  Branch (190:6): [True: 61, False: 46]
  ------------------
  191|     61|		rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     61|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  192|     61|		LOG_TEST_GOTO_ERR(ctx, rv, "Wrong card.");
  ------------------
  |  |  184|     61|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     61|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     61|	int _ret = (r); \
  |  |  |  |  178|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     61|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     61|		goto err; \
  |  |  |  |  182|     61|	} \
  |  |  |  |  183|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|     61|	}
  194|       |
  195|       |	/* Load ODF */
  196|     46|	rv = dump_ef(p15card->card, "3F0050155031", buf, &len);
  197|     46|	LOG_TEST_GOTO_ERR(ctx, rv, "Reading of ODF failed.");
  ------------------
  |  |  184|     46|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     46|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     46|	int _ret = (r); \
  |  |  |  |  178|     46|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 41]
  |  |  |  |  ------------------
  |  |  |  |  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|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 41]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|       |
  199|     41|	rv = parse_odf(buf, len, p15card);
  200|     41|	LOG_TEST_GOTO_ERR(ctx, rv, "Decoding of ODF failed.");
  ------------------
  |  |  184|     41|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     41|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     41|	int _ret = (r); \
  |  |  |  |  178|     41|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 3, False: 38]
  |  |  |  |  ------------------
  |  |  |  |  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|     41|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 38]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|       |	/* Decode EF.PrKDF, EF.PuKDF and EF.CDF */
  203|    141|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (203:30): [True: 103, False: 38]
  ------------------
  204|    103|		if (df->type == SC_PKCS15_PRKDF) {
  ------------------
  |  |  488|    103|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (204:7): [True: 19, False: 84]
  ------------------
  205|     19|			rv = sc_pkcs15_parse_df(p15card, df);
  206|     19|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     19|#define SC_SUCCESS				0
  ------------------
  |  Branch (206:8): [True: 18, False: 1]
  ------------------
  207|     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__
  |  |  ------------------
  ------------------
  208|     18|				       "Decoding of EF.PrKDF (%s) failed: %d",
  209|     18|				       sc_print_path(&df->path), rv);
  210|     18|			}
  211|     19|		}
  212|    103|		if (df->type == SC_PKCS15_PUKDF) {
  ------------------
  |  |  489|    103|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (212:7): [True: 26, False: 77]
  ------------------
  213|     26|			rv = sc_pkcs15_parse_df(p15card, df);
  214|     26|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     26|#define SC_SUCCESS				0
  ------------------
  |  Branch (214:8): [True: 25, False: 1]
  ------------------
  215|     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__
  |  |  ------------------
  ------------------
  216|     25|				       "Decoding of EF.PuKDF (%s) failed: %d",
  217|     25|				       sc_print_path(&df->path), rv);
  218|     25|			}
  219|     26|		}
  220|    103|		if (df->type == SC_PKCS15_CDF) {
  ------------------
  |  |  492|    103|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (220:7): [True: 5, False: 98]
  ------------------
  221|      5|			rv = sc_pkcs15_parse_df(p15card, df);
  222|      5|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|      5|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:8): [True: 4, False: 1]
  ------------------
  223|      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__
  |  |  ------------------
  ------------------
  224|      4|				       "Decoding of EF.CDF (%s) failed: %d",
  225|      4|				       sc_print_path(&df->path), rv);
  226|      4|			}
  227|      5|		}
  228|    103|		if (df->type == SC_PKCS15_DODF) {
  ------------------
  |  |  495|    103|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (228:7): [True: 27, False: 76]
  ------------------
  229|     27|			rv = sc_pkcs15_parse_df(p15card, df);
  230|     27|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     27|#define SC_SUCCESS				0
  ------------------
  |  Branch (230:8): [True: 24, False: 3]
  ------------------
  231|     24|				sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  232|     24|				       "Decoding of EF.DODF (%s) failed: %d",
  233|     24|				       sc_print_path(&df->path), rv);
  234|     24|			}
  235|     27|		}
  236|    103|	}
  237|       |
  238|       |	/* Perform required fixes */
  239|     38|	p15_obj = p15card->obj_list;
  240|     38|	while (p15_obj != NULL) {
  ------------------
  |  Branch (240:9): [True: 0, False: 38]
  ------------------
  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|     38|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|       |
  269|    543|err:
  270|    543|	sc_pkcs15_card_clear(p15card);
  271|    543|	p15card->opts.use_pin_cache = use_pin_cache_backup;
  272|    543|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    543|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    543|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    543|	int _ret = r; \
  |  |  |  |  155|    543|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 543, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    543|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    543|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 543, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    543|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    543|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    543|	return _ret; \
  |  |  |  |  163|    543|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  273|    543|}
pkcs15-dnie.c:dump_ef:
   42|    627|{
   43|    627|	int rv;
   44|    627|	sc_file_t *file = NULL;
   45|    627|	sc_path_t scpath;
   46|    627|	sc_format_path(path, &scpath);
   47|    627|	rv = sc_select_file(card, &scpath, &file);
   48|    627|	if (rv < 0) {
  ------------------
  |  Branch (48:6): [True: 400, False: 227]
  ------------------
   49|    400|		sc_file_free(file);
   50|    400|		return rv;
   51|    400|	}
   52|    227|	if (file->size > *buf_len) {
  ------------------
  |  Branch (52:6): [True: 34, False: 193]
  ------------------
   53|     34|		sc_file_free(file);
   54|     34|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     34|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   55|     34|	}
   56|    193|	rv = sc_read_binary(card, 0, buf, file->size, 0);
   57|    193|	sc_file_free(file);
   58|    193|	if (rv < 0)
  ------------------
  |  Branch (58:6): [True: 5, False: 188]
  ------------------
   59|      5|		return rv;
   60|    188|	*buf_len = rv;
   61|       |
   62|    188|	return SC_SUCCESS;
  ------------------
  |  |   28|    188|#define SC_SUCCESS				0
  ------------------
   63|    193|}
pkcs15-dnie.c:parse_odf:
  101|     41|{
  102|     41|	const u8 *p = buf;
  103|     41|	size_t left = buflen;
  104|     41|	int r, i, type;
  105|     41|	sc_path_t path;
  106|     41|	struct sc_asn1_entry asn1_obj_or_path[] = {
  107|     41|		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  174|     41|#define SC_ASN1_PATH			256
  ------------------
              		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  141|     41|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  162|     41|#define SC_ASN1_SEQUENCE                16
  ------------------
  108|     41|		 &path, NULL},
  109|     41|		{NULL, 0, 0, 0, NULL, NULL}
  110|     41|	};
  111|     41|	struct sc_asn1_entry asn1_odf[10];
  112|       |
  113|     41|	sc_path_t path_prefix;
  114|       |
  115|     41|	sc_format_path("3F005015", &path_prefix);
  116|       |
  117|     41|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  118|    410|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (118:14): [True: 369, False: 41]
  ------------------
  119|    369|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  120|    156|	while (left > 0) {
  ------------------
  |  Branch (120:9): [True: 154, False: 2]
  ------------------
  121|    154|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left,
  122|    154|					  &p, &left);
  123|    154|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    154|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (123:7): [True: 36, False: 118]
  ------------------
  124|     36|			break;
  125|    118|		if (r < 0)
  ------------------
  |  Branch (125:7): [True: 3, False: 115]
  ------------------
  126|      3|			return r;
  127|    115|		type = r;
  128|    115|		r = sc_pkcs15_make_absolute_path(&path_prefix, &path);
  129|    115|		if (r < 0)
  ------------------
  |  Branch (129:7): [True: 0, False: 115]
  ------------------
  130|      0|			return r;
  131|    115|		r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  132|    115|		if (r)
  ------------------
  |  Branch (132:7): [True: 0, False: 115]
  ------------------
  133|      0|			return r;
  134|    115|	}
  135|     38|	return 0;
  136|     41|}

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

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

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

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

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

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

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

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

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

sc_pkcs15emu_itacns_init_ex:
  881|  10.7k|{
  882|  10.7k|	sc_card_t *card = p15card->card;
  883|  10.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  10.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  10.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  10.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 10.7k]
  |  |  ------------------
  ------------------
  884|       |
  885|       |	/* Check card */
  886|  10.7k|	if (! (
  887|  10.7k|			(card->type > SC_CARD_TYPE_ITACNS_BASE &&
  ------------------
  |  Branch (887:5): [True: 3.65k, False: 7.12k]
  ------------------
  888|  3.65k|			card->type < SC_CARD_TYPE_ITACNS_BASE + 1000)
  ------------------
  |  Branch (888:4): [True: 231, False: 3.42k]
  ------------------
  889|  10.5k|		|| card->type == SC_CARD_TYPE_CARDOS_CIE_V1)
  ------------------
  |  Branch (889:6): [True: 0, False: 10.5k]
  ------------------
  890|  10.7k|		)
  891|  10.5k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  10.5k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  892|       |
  893|       |	/* Init card */
  894|    231|	return itacns_init(p15card);
  895|  10.7k|}
pkcs15-itacns.c:itacns_init:
  761|    231|{
  762|    231|	int r;
  763|    231|	sc_path_t path;
  764|    231|	int certificate_count = 0;
  765|    231|	int found_certs;
  766|    231|	int card_is_cie_v1, cns0_secenv;
  767|       |
  768|    231|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    231|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    231|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    231|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 231]
  |  |  ------------------
  ------------------
  769|       |
  770|    231|	set_string(&p15card->tokeninfo->label, p15card->card->name);
  771|    231|	if(p15card->card->drv_data) {
  ------------------
  |  Branch (771:5): [True: 231, False: 0]
  ------------------
  772|    231|		unsigned int mask_code, ic_code;
  773|    231|		char buffer[256];
  774|    231|		itacns_drv_data_t *data =
  775|    231|			(itacns_drv_data_t*) p15card->card->drv_data;
  776|    231|		mask_code = data->mask_manufacturer_code;
  777|    231|		if (mask_code >= sizeof(itacns_mask_manufacturers)
  ------------------
  |  Branch (777:7): [True: 38, False: 193]
  ------------------
  778|    231|			/sizeof(itacns_mask_manufacturers[0]))
  779|     38|			mask_code = 0;
  780|    231|		ic_code = data->ic_manufacturer_code;
  781|    231|		if (ic_code >= sizeof(iso7816_ic_manufacturers)
  ------------------
  |  Branch (781:7): [True: 207, False: 24]
  ------------------
  782|    231|			/sizeof(iso7816_ic_manufacturers[0]))
  783|    207|			ic_code = 0;
  784|    231|		snprintf(buffer, sizeof(buffer), "IC: %s; mask: %s",
  785|    231|			iso7816_ic_manufacturers[ic_code],
  786|    231|			itacns_mask_manufacturers[mask_code]);
  787|    231|		set_string(&p15card->tokeninfo->manufacturer_id, buffer);
  788|    231|	}
  789|       |
  790|       |	/* Read and set serial */
  791|    231|	{
  792|    231|		u8 serial[17];
  793|    231|		int bytes;
  794|    231|		sc_format_path(path_serial, &path);
  795|    231|		bytes = loadFile(p15card, &path, serial, 16);
  796|    231|		if (bytes < 0) return bytes;
  ------------------
  |  Branch (796:7): [True: 87, False: 144]
  ------------------
  797|    144|		if (bytes > 16) return -1;
  ------------------
  |  Branch (797:7): [True: 0, False: 144]
  ------------------
  798|    144|		serial[bytes] = '\0';
  799|    144|		set_string(&p15card->tokeninfo->serial_number, (char*)serial);
  800|    144|	}
  801|       |
  802|       |	/* Is the card a CIE v1? */
  803|      0|	card_is_cie_v1 =
  804|    144|		   (p15card->card->type == SC_CARD_TYPE_ITACNS_CIE_V1)
  ------------------
  |  Branch (804:6): [True: 129, False: 15]
  ------------------
  805|     15|		|| (p15card->card->type == SC_CARD_TYPE_CARDOS_CIE_V1);
  ------------------
  |  Branch (805:6): [True: 0, False: 15]
  ------------------
  806|    144|	cns0_secenv = (card_is_cie_v1 ? 0x31 : 0x01);
  ------------------
  |  Branch (806:17): [True: 129, False: 15]
  ------------------
  807|       |
  808|       |	/* If it's a Siemens CIE v1 card, set algo flags accordingly. */
  809|    144|	if (card_is_cie_v1) {
  ------------------
  |  Branch (809:6): [True: 129, False: 15]
  ------------------
  810|    129|		int i;
  811|    258|		for (i = 0; i < p15card->card->algorithm_count; i++) {
  ------------------
  |  Branch (811:15): [True: 129, False: 129]
  ------------------
  812|    129|			sc_algorithm_info_t *info =
  813|    129|				&p15card->card->algorithms[i];
  814|       |
  815|    129|			if (info->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    129|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (815:8): [True: 0, False: 129]
  ------------------
  816|      0|				continue;
  817|    129|			info->flags &= ~(SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|    129|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  818|    129|				| SC_ALGORITHM_RSA_HASH_NONE);
  ------------------
  |  |  133|    129|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  819|    129|			info->flags |= (SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    129|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|    129|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|    129|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  820|    129|				| SC_ALGORITHM_RSA_HASHES);
  ------------------
  |  |  142|    129|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  821|    129|		}
  822|    129|	}
  823|       |
  824|       |	/* Data files */
  825|    144|	r = itacns_add_data_files(p15card);
  826|    144|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    144|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    144|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    144|	int _ret = (r); \
  |  |  |  |  178|    144|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 144]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    144|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 144]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|    144|		"Could not add data files");
  828|       |
  829|       |	/*** Certificate and keys. ***/
  830|       |	/* Standard CNS */
  831|    144|	r = itacns_check_and_add_keyset(p15card, "CNS0", cns0_secenv,
  832|    144|		0, "3F0011001101", "3F003F01", NULL,
  833|    144|		0x10, &found_certs);
  834|    144|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    144|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    144|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    144|	int _ret = (r); \
  |  |  |  |  178|    144|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 68, False: 76]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     68|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     68|		goto err; \
  |  |  |  |  182|     68|	} \
  |  |  |  |  183|    144|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 76]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  835|     76|		"Could not add CNS0");
  836|     76|	certificate_count += found_certs;
  837|       |
  838|       |	/* Infocamere 1204 */
  839|     76|	r = itacns_check_and_add_keyset(p15card, "CNS01", 0x21,
  840|     76|		5, "3F002FFF8228", NULL, "3F002FFF0000",
  841|     76|		0x10, &found_certs);
  842|     76|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  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: 42, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     42|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     42|		goto err; \
  |  |  |  |  182|     42|	} \
  |  |  |  |  183|     76|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  843|     34|		"Could not add CNS01");
  844|     34|	certificate_count += found_certs;
  845|       |
  846|       |	/* Digital signature */
  847|     34|	r = itacns_check_and_add_keyset(p15card, "CNS1", 0x10,
  848|     34|		0, "3F0014009010", "3F00140081108010", "3F0014008110",
  849|     34|		0x1a, &found_certs);
  850|     34|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|     34|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     34|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     34|	int _ret = (r); \
  |  |  |  |  178|     34|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 24, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     24|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     24|		goto err; \
  |  |  |  |  182|     24|	} \
  |  |  |  |  183|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|     10|		"Could not add CNS1");
  852|     10|	certificate_count += found_certs;
  853|       |
  854|       |	/* Idemia card */
  855|     10|	r = itacns_check_and_add_keyset(p15card, "CNS1", 0x02,
  856|     10|		0, "3F00140090012002", "3F0011001102", "3F0014009002",
  857|     10|		0x10, &found_certs);
  858|     10|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|      5|		"Could not add CNS1");
  860|      5|	certificate_count += found_certs;
  861|       |
  862|       |	/* Did we find anything? */
  863|      5|	if (certificate_count == 0)
  ------------------
  |  Branch (863:6): [True: 5, False: 0]
  ------------------
  864|      5|		sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL,
  ------------------
  |  |   70|      5|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  865|      5|			"Warning: no certificates found!");
  866|       |
  867|       |	/* Back to Master File */
  868|      5|	sc_format_path("3F00", &path);
  869|      5|	r = sc_select_file(p15card->card, &path, NULL);
  870|      5|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|      5|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      5|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      5|	int _ret = (r); \
  |  |  |  |  178|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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|      5|} 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|    138|err:
  876|    138|	sc_pkcs15_card_clear(p15card);
  877|    138|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|    138|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    138|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    138|	int _ret = r; \
  |  |  |  |  155|    138|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 138, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    138|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    138|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 138, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    138|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    138|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    138|	return _ret; \
  |  |  |  |  163|    138|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  878|    138|}
pkcs15-itacns.c:loadFile:
  169|    293|{
  170|    293|	int sc_res;
  171|    293|	SC_FUNC_CALLED(p15card->card->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]
  |  |  ------------------
  ------------------
  172|       |
  173|    293|	sc_res = sc_select_file(p15card->card, path, NULL);
  174|    293|	if(sc_res != SC_SUCCESS)
  ------------------
  |  |   28|    293|#define SC_SUCCESS				0
  ------------------
  |  Branch (174:5): [True: 87, False: 206]
  ------------------
  175|     87|		return sc_res;
  176|       |
  177|    206|	sc_res = sc_read_binary(p15card->card, 0, buf, buflen, 0);
  178|    206|	return sc_res;
  179|    293|}
pkcs15-itacns.c:itacns_add_data_files:
  482|    144|{
  483|    144|	const size_t array_size =
  484|    144|		sizeof(itacns_data_files)/sizeof(itacns_data_files[0]);
  485|    144|	unsigned int i;
  486|    144|	int rv;
  487|    144|	sc_pkcs15_data_t *p15_personaldata = NULL;
  488|    144|	sc_pkcs15_data_info_t dinfo;
  489|    144|	struct sc_pkcs15_object *objs[32];
  490|    144|	struct sc_pkcs15_data_info *cinfo;
  491|    144|	int private_obj;
  492|       |
  493|  2.16k|	for(i=0; i < array_size; i++) {
  ------------------
  |  Branch (493:11): [True: 2.01k, False: 144]
  ------------------
  494|  2.01k|		sc_path_t path;
  495|  2.01k|		sc_pkcs15_data_info_t data;
  496|  2.01k|		sc_pkcs15_object_t    obj;
  497|       |
  498|  2.01k|		if (itacns_data_files[i].cie_only &&
  ------------------
  |  Branch (498:7): [True: 576, False: 1.44k]
  ------------------
  499|    576|			p15card->card->type != SC_CARD_TYPE_ITACNS_CIE_V2)
  ------------------
  |  Branch (499:4): [True: 572, False: 4]
  ------------------
  500|    572|			continue;
  501|       |
  502|  1.44k|		sc_format_path(itacns_data_files[i].path, &path);
  503|       |
  504|  1.44k|		memset(&data, 0, sizeof(data));
  505|  1.44k|		memset(&obj, 0, sizeof(obj));
  506|  1.44k|		strlcpy(data.app_label, itacns_data_files[i].label,
  ------------------
  |  |   43|  1.44k|#define strlcpy _strlcpy
  ------------------
  507|  1.44k|			sizeof(data.app_label));
  508|  1.44k|		strlcpy(obj.label, itacns_data_files[i].label,
  ------------------
  |  |   43|  1.44k|#define strlcpy _strlcpy
  ------------------
  509|  1.44k|			sizeof(obj.label));
  510|  1.44k|		data.path = path;
  511|  1.44k|		rv = sc_pkcs15emu_add_data_object(p15card, &obj, &data);
  512|  1.44k|		LOG_TEST_RET(p15card->card->ctx, rv,
  ------------------
  |  |  174|  1.44k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.44k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.44k|	int _ret = (r); \
  |  |  |  |  168|  1.44k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.44k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.44k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.44k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|  1.44k|			"Could not add data file");
  514|  1.44k|	}
  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|    144|	memset(&dinfo, 0, sizeof(dinfo));
  522|    144|	strlcpy(dinfo.app_label, "EF_DatiPersonali", sizeof(dinfo.app_label));
  ------------------
  |  |   43|    144|#define strlcpy _strlcpy
  ------------------
  523|       |
  524|       |	/* Find EF_DatiPersonali */
  525|       |
  526|    144|	rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_DATA_OBJECT,
  ------------------
  |  |  442|    144|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  527|    144|		objs, 32);
  528|    144|	if(rv < 0) {
  ------------------
  |  Branch (528:5): [True: 0, False: 144]
  ------------------
  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|    433|	for(i=0; i<32; i++) {
  ------------------
  |  Branch (534:11): [True: 433, False: 0]
  ------------------
  535|    433|		cinfo = (struct sc_pkcs15_data_info *) objs[i]->data;
  536|    433|		if(!strcmp("EF_DatiPersonali", objs[i]->label))
  ------------------
  |  Branch (536:6): [True: 144, False: 289]
  ------------------
  537|    144|			break;
  538|    433|	}
  539|       |
  540|    144|	if(i>=32) {
  ------------------
  |  Branch (540:5): [True: 0, False: 144]
  ------------------
  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|    144|	private_obj = objs[i]->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    144|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  548|    144|	rv = sc_pkcs15_read_data_object(p15card, cinfo, private_obj, &p15_personaldata);
  549|    144|	if (rv) {
  ------------------
  |  Branch (549:6): [True: 53, False: 91]
  ------------------
  550|     53|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|     53|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  551|     53|			"Could not read EF_DatiPersonali: "
  552|     53|			"keeping generic card name");
  553|     53|		return SC_SUCCESS;
  ------------------
  |  |   28|     53|#define SC_SUCCESS				0
  ------------------
  554|     53|	}
  555|       |
  556|     91|	if (p15_personaldata->data) {
  ------------------
  |  Branch (556:6): [True: 69, False: 22]
  ------------------
  557|     69|		char fullname[160];
  558|     69|		if (get_name_from_EF_DatiPersonali(p15_personaldata->data,
  ------------------
  |  Branch (558:7): [True: 68, False: 1]
  ------------------
  559|     69|			p15_personaldata->data_len, fullname, sizeof(fullname))) {
  560|     68|			sc_log(p15card->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__
  |  |  ------------------
  ------------------
  561|     68|				"Could not parse EF_DatiPersonali: "
  562|     68|				"keeping generic card name");
  563|     68|			sc_pkcs15_free_data_object(p15_personaldata);
  564|     68|			free(cinfo->data.value);
  565|     68|			cinfo->data.value = NULL;
  566|     68|			return SC_SUCCESS;
  ------------------
  |  |   28|     68|#define SC_SUCCESS				0
  ------------------
  567|     68|		}
  568|      1|		set_string(&p15card->tokeninfo->label, fullname);
  569|      1|	}
  570|     23|	free(cinfo->data.value);
  571|     23|	cinfo->data.value = NULL;
  572|     23|	sc_pkcs15_free_data_object(p15_personaldata);
  573|     23|	return SC_SUCCESS;
  ------------------
  |  |   28|     23|#define SC_SUCCESS				0
  ------------------
  574|     91|}
pkcs15-itacns.c:get_name_from_EF_DatiPersonali:
  387|     69|{
  388|     69|	const unsigned int EF_personaldata_maxlen = 400;
  389|     69|	const unsigned int tlv_length_size = 6;
  390|     69|	char *file = NULL;
  391|     69|	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|     69|	if (EFdata_len < tlv_length_size) {
  ------------------
  |  Branch (397:6): [True: 11, False: 58]
  ------------------
  398|       |		/* We need at least 6 bytes for file length here */
  399|     11|		return -1;
  400|     11|	}
  401|     58|	file_size = hextoint((char*)EFdata, tlv_length_size);
  402|     58|	if (EFdata_len < (file_size + tlv_length_size)) {
  ------------------
  |  Branch (402:6): [True: 12, False: 46]
  ------------------
  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|     12|		return -1;
  408|     12|	}
  409|     46|	file = (char*)&EFdata[tlv_length_size];
  410|       |
  411|     46|	enum {
  412|     46|		f_issuer_code = 0,
  413|     46|		f_issuing_date,
  414|     46|		f_expiry_date,
  415|     46|		f_last_name,
  416|     46|		f_first_name,
  417|     46|		f_birth_date,
  418|     46|		f_sex,
  419|     46|		f_height,
  420|     46|		f_codice_fiscale,
  421|     46|		f_citizenship_code,
  422|     46|		f_birth_township_code,
  423|     46|		f_birth_country,
  424|     46|		f_birth_certificate,
  425|     46|		f_residence_township_code,
  426|     46|		f_residence_address,
  427|     46|		f_expat_notes
  428|     46|	};
  429|       |
  430|       |	/* Read the fields up to f_first_name */
  431|     46|	struct {
  432|     46|		int len;
  433|     46|		char value[256];
  434|     46|	} fields[f_first_name+1];
  435|     46|	int i=0; /* offset inside the file */
  436|     46|	int f; /* field number */
  437|       |
  438|     46|	if (file_size < 0)
  ------------------
  |  Branch (438:6): [True: 37, False: 9]
  ------------------
  439|     37|		return -1;
  440|       |
  441|       |	/*
  442|       |	 * This shouldn't happen, but let us be protected against wrong
  443|       |	 * or malicious cards
  444|       |	 */
  445|      9|	if(file_size > (int)EF_personaldata_maxlen - (int)tlv_length_size)
  ------------------
  |  Branch (445:5): [True: 0, False: 9]
  ------------------
  446|      0|		file_size = EF_personaldata_maxlen - tlv_length_size;
  447|       |
  448|       |
  449|      9|	memset(fields, 0, sizeof(fields));
  450|       |
  451|     26|	for(f=0; f<f_first_name+1; f++) {
  ------------------
  |  Branch (451:11): [True: 25, False: 1]
  ------------------
  452|     25|		int field_size;
  453|       |
  454|       |		/* Don't read beyond the allocated buffer */
  455|     25|		if(i+2 > file_size)
  ------------------
  |  Branch (455:6): [True: 2, False: 23]
  ------------------
  456|      2|			return -1;
  457|     23|		field_size = hextoint((char*) &file[i], 2);
  458|     23|		i += 2;
  459|       |
  460|     23|		if (field_size < 0
  ------------------
  |  Branch (460:7): [True: 2, False: 21]
  ------------------
  461|     21|				|| i + field_size > file_size
  ------------------
  |  Branch (461:8): [True: 4, False: 17]
  ------------------
  462|     17|				|| field_size >= (int)sizeof(fields[f].value))
  ------------------
  |  Branch (462:8): [True: 0, False: 17]
  ------------------
  463|      6|			return -1;
  464|       |
  465|     17|		fields[f].len = field_size;
  466|     17|		strncpy(fields[f].value, &file[i], field_size);
  467|     17|		fields[f].value[field_size] = '\0';
  468|     17|		i += field_size;
  469|     17|	}
  470|       |
  471|      1|	if (fields[f_first_name].len + fields[f_last_name].len + 1 >= name_len)
  ------------------
  |  Branch (471:6): [True: 0, False: 1]
  ------------------
  472|      0|		return -1;
  473|       |
  474|       |	/* the lengths are already checked that they will fit in buffer */
  475|      1|	snprintf(name, name_len, "%.*s %.*s",
  476|      1|		fields[f_first_name].len, fields[f_first_name].value,
  477|      1|		fields[f_last_name].len, fields[f_last_name].value);
  478|      1|	return 0;
  479|      1|}
pkcs15-itacns.c:hextoint:
  370|     81|{
  371|     81|	char hex[16];
  372|     81|	char *end;
  373|     81|	int res;
  374|       |
  375|     81|	if(len >= sizeof(hex))
  ------------------
  |  Branch (375:5): [True: 0, False: 81]
  ------------------
  376|      0|		return -1;
  377|     81|	strncpy(hex, src, len);
  378|     81|	hex[len] = '\0';
  379|     81|	res = (int)strtol(hex, &end, 0x10);
  380|     81|	if(end != (char*)&hex[len])
  ------------------
  |  Branch (380:5): [True: 39, False: 42]
  ------------------
  381|     39|		return -1;
  382|     42|	return res;
  383|     81|}
pkcs15-itacns.c:itacns_check_and_add_keyset:
  654|    264|{
  655|    264|	int r;
  656|    264|	sc_path_t path;
  657|    264|	sc_pkcs15_id_t cert_id;
  658|    264|	int ext_info_ok;
  659|    264|	int ku = 0, xku = 0;
  660|    264|	size_t modulus_len = 0;
  661|    264|	int pubkey_usage_flags = 0, prkey_usage_flags = 0;
  662|       |
  663|    264|	cert_id.len = 1;
  664|    264|	cert_id.value[0] = sec_env;
  665|    264|	*found_certificates = 0;
  666|       |
  667|       |	/* Certificate */
  668|    264|	if (!cert_path) {
  ------------------
  |  Branch (668:6): [True: 0, False: 264]
  ------------------
  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|    264|	sc_format_path(cert_path, &path);
  675|    264|	r = sc_select_file(p15card->card, &path, NULL);
  676|    264|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    264|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (676:6): [True: 19, False: 245]
  ------------------
  677|     19|		return 0;
  678|    245|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    245|#define SC_SUCCESS				0
  ------------------
  |  Branch (678:6): [True: 91, False: 154]
  ------------------
  679|     91|		sc_log(p15card->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__
  |  |  ------------------
  ------------------
  680|     91|			"Could not find certificate for %s", label);
  681|     91|		return r;
  682|     91|	}
  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|    154|	if (cert_offset) {
  ------------------
  |  Branch (689:6): [True: 62, False: 92]
  ------------------
  690|     62|		u8 certlen[3];
  691|     62|		memset(certlen, 0, sizeof certlen);
  692|     62|		r = loadFile(p15card, &path, certlen, sizeof(certlen));
  693|     62|		LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|     62|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     62|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     62|	int _ret = (r); \
  |  |  |  |  168|     62|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 55]
  |  |  |  |  ------------------
  |  |  |  |  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|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 55]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  694|     55|			"Could not read certificate file");
  695|     55|		if (r < 3)
  ------------------
  |  Branch (695:7): [True: 3, False: 52]
  ------------------
  696|      3|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  697|     52|		path.index = (int)cert_offset;
  698|     52|		path.count = (certlen[1] << 8) + certlen[2];
  699|       |		/* If those bytes are 00, then we are probably dealing with an
  700|       |		 * empty file. */
  701|     52|		if (path.count == 0)
  ------------------
  |  Branch (701:7): [True: 4, False: 48]
  ------------------
  702|      4|			return 0;
  703|     52|	}
  704|       |
  705|    140|	r = itacns_add_cert(p15card, SC_PKCS15_TYPE_CERT_X509, 0,
  ------------------
  |  |  439|    140|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  706|    140|		&path, &cert_id, label, 0, &ext_info_ok, &ku, &xku, &modulus_len);
  707|    140|	if (r == SC_ERROR_INVALID_ASN1_OBJECT)
  ------------------
  |  |   82|    140|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (707:6): [True: 102, False: 38]
  ------------------
  708|    102|		return 0;
  709|     38|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|     38|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     38|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     38|	int _ret = (r); \
  |  |  |  |  168|     38|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 38, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     38|} 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|    140|{
  190|    140|	int r;
  191|       |	/* const char *label = "Certificate"; */
  192|    140|	sc_pkcs15_cert_info_t info;
  193|    140|	sc_pkcs15_object_t    obj;
  194|    140|#ifdef ENABLE_OPENSSL
  195|    140|	X509 *x509;
  196|    140|	sc_pkcs15_cert_t *cert;
  197|    140|	int private_obj;
  198|    140|#endif
  199|       |
  200|    140|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    140|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    140|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    140|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 140]
  |  |  ------------------
  ------------------
  201|       |
  202|    140|	if(type != SC_PKCS15_TYPE_CERT_X509) {
  ------------------
  |  |  439|    140|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  |  Branch (202:5): [True: 0, False: 140]
  ------------------
  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|    140|	*ext_info_ok = 0;
  209|       |
  210|       |
  211|    140|	memset(&info, 0, sizeof(info));
  212|    140|	memset(&obj,  0, sizeof(obj));
  213|       |
  214|    140|	info.id                = *id;
  215|    140|	info.authority         = authority;
  216|    140|	if (path)
  ------------------
  |  Branch (216:6): [True: 140, False: 0]
  ------------------
  217|    140|		info.path = *path;
  218|       |
  219|    140|	strlcpy(obj.label, label, sizeof(obj.label));
  ------------------
  |  |   43|    140|#define strlcpy _strlcpy
  ------------------
  220|       |
  221|       |	/* If we have OpenSSL, read keyUsage */
  222|    140|#ifdef ENABLE_OPENSSL
  223|    140|	private_obj = obj_flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    140|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  224|    140|	r = sc_pkcs15_read_certificate(p15card, &info, private_obj, &cert);
  225|    140|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|    140|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    140|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    140|	int _ret = (r); \
  |  |  |  |  168|    140|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 140, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    140|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    140|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    140|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    140|		return _ret; \
  |  |  |  |  172|    140|	} \
  |  |  |  |  173|    140|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  226|      0|		"Could not read X.509 certificate");
  227|       |
  228|      0|	{
  229|      0|		const u8 *throwaway = cert->data.value;
  230|      0|		x509 = d2i_X509(NULL, &throwaway, cert->data.len);
  231|      0|	}
  232|       |
  233|      0|	if (cert->key && cert->key->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (233:6): [True: 0, False: 0]
  |  Branch (233:19): [True: 0, False: 0]
  ------------------
  234|      0|		*modulus_len = cert->key->u.rsa.modulus.len * 8;
  235|      0|	}
  236|       |
  237|      0|	sc_pkcs15_free_certificate(cert);
  238|      0|	if (!x509) {
  ------------------
  |  Branch (238:6): [True: 0, False: 0]
  ------------------
  239|      0|		sc_log_openssl(p15card->card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  240|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  241|      0|	}
  242|      0|	X509_check_purpose(x509, -1, 0);
  243|       |
  244|      0|	if(X509_get_extension_flags(x509) & EXFLAG_KUSAGE) {
  ------------------
  |  Branch (244:5): [True: 0, False: 0]
  ------------------
  245|      0|		*ext_info_ok = 1;
  246|      0|		*key_usage = X509_get_key_usage(x509);
  247|      0|		*x_key_usage = X509_get_extended_key_usage(x509);
  248|      0|	}
  249|      0|	OPENSSL_free(x509);
  250|       |
  251|      0|#endif /* ENABLE_OPENSSL */
  252|       |
  253|      0|	obj.flags = obj_flags;
  254|      0|	r = sc_pkcs15emu_add_x509_cert(p15card, &obj, &info);
  255|      0|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  256|      0|		"Could not add X.509 certificate");
  257|       |
  258|      0|	return r;
  259|      0|}

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

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

sc_pkcs15emu_nqapplet_init_ex:
  179|  6.94k|{
  180|  6.94k|	int rv = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.94k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  181|  6.94k|	sc_context_t *ctx;
  182|  6.94k|	sc_card_t *card;
  183|       |
  184|  6.94k|	if (!p15card || !p15card->card || !p15card->card->ctx) {
  ------------------
  |  Branch (184:6): [True: 0, False: 6.94k]
  |  Branch (184:18): [True: 0, False: 6.94k]
  |  Branch (184:36): [True: 0, False: 6.94k]
  ------------------
  185|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  186|      0|	}
  187|       |
  188|  6.94k|	card = p15card->card;
  189|  6.94k|	ctx = card->ctx;
  190|       |
  191|  6.94k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  6.94k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.94k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.94k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.94k]
  |  |  ------------------
  ------------------
  192|       |
  193|  6.94k|	if (card->type < SC_CARD_TYPE_NQ_APPLET || card->type > SC_CARD_TYPE_NQ_APPLET_RFID) {
  ------------------
  |  Branch (193:6): [True: 6.94k, False: 2]
  |  Branch (193:45): [True: 2, False: 0]
  ------------------
  194|  6.94k|		sc_log(p15card->card->ctx, "Unsupported card type: %d", card->type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  195|  6.94k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.94k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  196|  6.94k|	}
  197|       |
  198|      0|	rv = add_nqapplet_objects(p15card);
  199|      0|	LOG_TEST_GOTO_ERR(ctx, rv, "Failed to add PKCS15");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|       |
  201|      0|	if (aid != NULL) {
  ------------------
  |  Branch (201:6): [True: 0, False: 0]
  ------------------
  202|      0|		struct sc_file *file = sc_file_new();
  203|      0|		if (file != NULL) {
  ------------------
  |  Branch (203:7): [True: 0, False: 0]
  ------------------
  204|       |			/* PKCS11 depends on the file_app object, provide MF */
  205|      0|			sc_format_path("3f00", &file->path);
  206|      0|			sc_file_free(p15card->file_app);
  207|      0|			p15card->file_app = file;
  208|      0|		}
  209|      0|	}
  210|       |
  211|      0|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  212|       |
  213|      0|	p15card->tokeninfo = sc_pkcs15_tokeninfo_new();
  214|      0|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (214:6): [True: 0, False: 0]
  ------------------
  215|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  216|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "unable to create tokeninfo struct");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|      0|	} else {
  218|      0|		char serial_hex[SC_MAX_SERIALNR * 2 + 2];
  219|       |
  220|      0|		sc_bin_to_hex(card->serialnr.value, card->serialnr.len, serial_hex, sizeof(serial_hex), 0);
  221|      0|		set_string(&p15card->tokeninfo->serial_number, serial_hex);
  222|      0|		set_string(&p15card->tokeninfo->label, name_Card);
  223|      0|		set_string(&p15card->tokeninfo->manufacturer_id, name_Vendor);
  224|      0|		p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|      0|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  225|      0|	}
  226|       |
  227|      0|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  228|      0|err:
  229|      0|	sc_pkcs15_card_clear(p15card);
  230|      0|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  231|      0|}

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

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

sc_pkcs15_decode_aodf_entry:
   86|    241|{
   87|    241|	sc_context_t *ctx = p15card->card->ctx;
   88|    241|	struct sc_pkcs15_auth_info info;
   89|    241|	int r;
   90|    241|	size_t flags_len = sizeof(info.attrs.pin.flags);
   91|    241|	size_t derived_len = sizeof(info.attrs.authkey.derived);
   92|    241|	size_t padchar_len = 1;
   93|    241|	struct sc_asn1_entry asn1_com_ao_attr[2];
   94|    241|	struct sc_asn1_entry asn1_pin_attr[10], asn1_type_pin_attr[2];
   95|    241|	struct sc_asn1_entry asn1_authkey_attr[3], asn1_type_authkey_attr[2];
   96|    241|	struct sc_asn1_entry asn1_auth_type[2];
   97|    241|	struct sc_asn1_entry asn1_auth_type_choice[4];
   98|    241|	struct sc_asn1_pkcs15_object pin_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_pin_attr };
   99|    241|	struct sc_asn1_pkcs15_object authkey_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_authkey_attr };
  100|       |
  101|    241|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_ASN1);
  ------------------
  |  |  148|    241|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    241|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    241|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 241]
  |  |  ------------------
  ------------------
  102|       |
  103|    241|	sc_copy_asn1_entry(c_asn1_auth_type, asn1_auth_type);
  104|    241|	sc_copy_asn1_entry(c_asn1_auth_type_choice, asn1_auth_type_choice);
  105|       |
  106|    241|	sc_copy_asn1_entry(c_asn1_com_ao_attr, asn1_com_ao_attr);
  107|       |
  108|    241|	sc_copy_asn1_entry(c_asn1_type_pin_attr, asn1_type_pin_attr);
  109|    241|	sc_copy_asn1_entry(c_asn1_pin_attr, asn1_pin_attr);
  110|       |
  111|    241|	sc_copy_asn1_entry(c_asn1_type_authkey_attr, asn1_type_authkey_attr);
  112|    241|	sc_copy_asn1_entry(c_asn1_authkey_attr, asn1_authkey_attr);
  113|       |
  114|    241|	sc_format_asn1_entry(asn1_auth_type + 0, asn1_auth_type_choice, NULL, 0);
  115|    241|	sc_format_asn1_entry(asn1_auth_type_choice + 0, &pin_obj, NULL, 0);	/* 'pin' */
  116|    241|	sc_format_asn1_entry(asn1_auth_type_choice + 2, &authkey_obj, NULL, 0);	/* 'authKey' */
  117|       |
  118|       |	/* pinAttributes */
  119|    241|	sc_format_asn1_entry(asn1_type_pin_attr + 0, asn1_pin_attr, NULL, 0);
  120|    241|	sc_format_asn1_entry(asn1_pin_attr + 0, &info.attrs.pin.flags, &flags_len, 0);
  121|    241|	sc_format_asn1_entry(asn1_pin_attr + 1, &info.attrs.pin.type, NULL, 0);
  122|    241|	sc_format_asn1_entry(asn1_pin_attr + 2, &info.attrs.pin.min_length, NULL, 0);
  123|    241|	sc_format_asn1_entry(asn1_pin_attr + 3, &info.attrs.pin.stored_length, NULL, 0);
  124|    241|	sc_format_asn1_entry(asn1_pin_attr + 4, &info.attrs.pin.max_length, NULL, 0);
  125|    241|	sc_format_asn1_entry(asn1_pin_attr + 5, &info.attrs.pin.reference, NULL, 0);
  126|    241|	sc_format_asn1_entry(asn1_pin_attr + 6, &info.attrs.pin.pad_char, &padchar_len, 0);
  127|       |
  128|       |	/* authKeyAttributes */
  129|    241|	sc_format_asn1_entry(asn1_type_authkey_attr + 0, asn1_authkey_attr, NULL, 0);
  130|    241|	sc_format_asn1_entry(asn1_authkey_attr + 0, &info.attrs.authkey.derived, &derived_len, 0);
  131|    241|	sc_format_asn1_entry(asn1_authkey_attr + 1, &info.attrs.authkey.skey_id, NULL, 0);
  132|       |
  133|       |	/* We don't support lastPinChange yet. */
  134|    241|	sc_format_asn1_entry(asn1_pin_attr + 8, &info.path, NULL, 0);
  135|       |
  136|    241|	sc_format_asn1_entry(asn1_com_ao_attr + 0, &info.auth_id, NULL, 0);
  137|       |
  138|       |	/* Fill in defaults */
  139|    241|	memset(&info, 0, sizeof(info));
  140|    241|	info.tries_left = -1;
  141|    241|	info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    241|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  142|       |
  143|    241|	r = sc_asn1_decode(ctx, asn1_auth_type, *buf, *buflen, buf, buflen);
  144|    241|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    241|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (144:6): [True: 11, False: 230]
  ------------------
  145|     11|		return r;
  146|    230|	LOG_TEST_RET(ctx, r, "ASN.1 decoding 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: 79, False: 151]
  |  |  |  |  ------------------
  |  |  |  |  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|    230|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 151]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  147|       |
  148|    151|	if (asn1_auth_type_choice[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    151|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (148:6): [True: 149, False: 2]
  ------------------
  149|    149|		sc_log(ctx, "AuthType: PIN");
  ------------------
  |  |   71|    149|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  150|    149|		obj->type = SC_PKCS15_TYPE_AUTH_PIN;
  ------------------
  |  |  445|    149|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  151|    149|		info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    149|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  152|    149|		info.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|    149|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  153|       |
  154|    149|		if (info.attrs.pin.max_length == 0) {
  ------------------
  |  Branch (154:7): [True: 130, False: 19]
  ------------------
  155|    130|			if (p15card->card->max_pin_len != 0)
  ------------------
  |  Branch (155:8): [True: 0, False: 130]
  ------------------
  156|      0|				info.attrs.pin.max_length = p15card->card->max_pin_len;
  157|    130|			else if (info.attrs.pin.stored_length != 0)
  ------------------
  |  Branch (157:13): [True: 126, False: 4]
  ------------------
  158|    126|				info.attrs.pin.max_length = info.attrs.pin.type != SC_PKCS15_PIN_TYPE_BCD ?
  ------------------
  |  |   88|    126|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (158:33): [True: 120, False: 6]
  ------------------
  159|    120|					info.attrs.pin.stored_length : 2 * info.attrs.pin.stored_length;
  160|      4|			else
  161|      4|				info.attrs.pin.max_length = 8; /* shouldn't happen */
  162|    130|		}
  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|    149|		if (info.attrs.pin.reference < 0)
  ------------------
  |  Branch (169:7): [True: 1, False: 148]
  ------------------
  170|      1|			info.attrs.pin.reference += 256;
  171|       |
  172|    149|		if (info.attrs.pin.flags & SC_PKCS15_PIN_FLAG_LOCAL)   {
  ------------------
  |  |   55|    149|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  |  Branch (172:7): [True: 9, False: 140]
  ------------------
  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|      9|			if (!info.path.len)   {
  ------------------
  |  Branch (175:8): [True: 8, False: 1]
  ------------------
  176|       |				/* Give priority to AID defined in the application DDO */
  177|      8|				if (p15card->app && p15card->app->ddo.aid.len)
  ------------------
  |  Branch (177:9): [True: 0, False: 8]
  |  Branch (177:25): [True: 0, False: 0]
  ------------------
  178|      0|					info.path.aid = p15card->app->ddo.aid;
  179|      8|				else if (p15card->file_app && p15card->file_app->path.len)
  ------------------
  |  Branch (179:14): [True: 8, False: 0]
  |  Branch (179:35): [True: 8, False: 0]
  ------------------
  180|      8|					info.path = p15card->file_app->path;
  181|      0|				else
  182|      0|					return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  183|      8|			}
  184|      9|		}
  185|    149|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoded PIN(ref:%X,path:%s)", info.attrs.pin.reference, sc_print_path(&info.path));
  ------------------
  |  |   70|    149|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  186|    149|	}
  187|      2|	else if (asn1_auth_type_choice[1].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|      2|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (187:11): [True: 2, False: 0]
  ------------------
  188|      2|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "BIO authentication object not yet supported");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|      2|	}
  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|    149|	obj->data = malloc(sizeof(info));
  203|    149|	if (obj->data == NULL)
  ------------------
  |  Branch (203:6): [True: 0, False: 149]
  ------------------
  204|    149|		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|    149|	memcpy(obj->data, &info, sizeof(info));
  206|       |
  207|    149|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_SUCCESS);
  ------------------
  |  |  153|    149|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    149|	int _ret = r; \
  |  |  155|    149|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 149, False: 0]
  |  |  ------------------
  |  |  156|    149|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 149]
  |  |  ------------------
  |  |  157|    149|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    149|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    149|	return _ret; \
  |  |  163|    149|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  208|    149|}
sc_pkcs15_verify_pin:
  299|    461|{
  300|    461|	struct sc_context *ctx = p15card->card->ctx;
  301|    461|	struct sc_pkcs15_auth_info *auth_info;
  302|    461|	int r;
  303|       |
  304|    461|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    461|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    461|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    461|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    461|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 461]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|       |
  306|    461|	if (!pin_obj || !pin_obj->data)
  ------------------
  |  Branch (306:6): [True: 0, False: 461]
  |  Branch (306:18): [True: 0, False: 461]
  ------------------
  307|    461|		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|    461|	auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  309|       |
  310|       |	/* Check the provided pin matches pin requirements */
  311|    461|	r = _validate_pin(p15card, auth_info, pinlen);
  312|       |
  313|    461|	if (r)
  ------------------
  |  Branch (313:6): [True: 167, False: 294]
  ------------------
  314|    461|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|       |
  316|    294|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pincode, pinlen);
  317|       |
  318|    294|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    294|#define SC_SUCCESS				0
  ------------------
  |  Branch (318:6): [True: 211, False: 83]
  ------------------
  319|    211|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  320|       |
  321|    294|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    294|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    294|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    294|	int _ret = r; \
  |  |  |  |  155|    294|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 294, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    294|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     83|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 83, False: 211]
  |  |  |  |  ------------------
  |  |  |  |  157|    294|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    294|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    294|	return _ret; \
  |  |  |  |  163|    294|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  322|    294|}
_sc_pkcs15_verify_pin:
  328|    323|{
  329|    323|	return sc_pkcs15_verify_pin_with_session_pin(p15card, pin_obj, pincode,
  330|    323|			pinlen, NULL, NULL);
  331|    323|}
sc_pkcs15_verify_pin_with_session_pin:
  344|    323|{
  345|    323|	struct sc_context *ctx = p15card->card->ctx;
  346|    323|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  347|    323|	int r;
  348|    323|	sc_card_t *card;
  349|    323|	struct sc_pin_cmd_data data;
  350|       |
  351|    323|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    323|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    323|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    323|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    323|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 323]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|    323|	sc_log(ctx, "PIN(type:%X; method:%X; value(%p:%zu)",
  ------------------
  |  |   71|    323|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  353|    323|			auth_info->auth_type, auth_info->auth_method, pincode, pinlen);
  354|    323|	card = p15card->card;
  355|       |
  356|    323|	if (pinlen > SC_MAX_PIN_SIZE) {
  ------------------
  |  |   40|    323|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (356:6): [True: 0, False: 323]
  ------------------
  357|      0|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  358|      0|				NOTIFY_PIN_BAD);
  359|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  360|      0|	}
  361|       |
  362|       |	/* Initialize arguments */
  363|    323|	memset(&data, 0, sizeof(data));
  364|    323|	data.pin_type = auth_info->auth_method;
  365|       |
  366|    323|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    323|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (366:6): [True: 323, False: 0]
  ------------------
  367|    323|		data.pin_reference = auth_info->attrs.pin.reference;
  368|    323|		data.pin1.min_length = auth_info->attrs.pin.min_length;
  369|    323|		data.pin1.max_length = auth_info->attrs.pin.max_length;
  370|    323|		data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  371|    323|		data.pin1.pad_char = auth_info->attrs.pin.pad_char;
  372|    323|		data.pin1.data = pincode;
  373|    323|		data.pin1.len = pinlen;
  374|       |
  375|    323|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    323|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (375:7): [True: 84, False: 239]
  ------------------
  376|     84|			data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     84|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  377|       |
  378|    323|		switch (auth_info->attrs.pin.type) {
  379|      0|		case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      0|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (379:3): [True: 0, False: 323]
  ------------------
  380|      0|			data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      0|#define SC_PIN_ENCODING_BCD	1
  ------------------
  381|      0|			break;
  382|    271|		case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    271|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (382:3): [True: 271, False: 52]
  ------------------
  383|    271|			data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    271|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  384|    271|			break;
  385|     52|		default:
  ------------------
  |  Branch (385:3): [True: 52, False: 271]
  ------------------
  386|       |			/* assume/hope the card driver knows how to encode the pin */
  387|     52|			data.pin1.encoding = 0;
  388|    323|		}
  389|    323|	}
  390|      0|	else if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY)   {
  ------------------
  |  |   96|      0|#define SC_PKCS15_PIN_AUTH_TYPE_AUTH_KEY		2
  ------------------
  |  Branch (390:11): [True: 0, False: 0]
  ------------------
  391|      0|		struct sc_pkcs15_object *skey_obj = NULL;
  392|      0|		struct sc_pkcs15_id *skey_id =  &auth_info->attrs.authkey.skey_id;
  393|      0|		struct sc_pkcs15_skey_info *skey_info = NULL;
  394|       |
  395|      0|		r = sc_pkcs15_find_skey_by_id(p15card, skey_id, &skey_obj);
  396|      0|		if (r)   {
  ------------------
  |  Branch (396:7): [True: 0, False: 0]
  ------------------
  397|      0|			sc_log(ctx, "cannot find secret key with id:%s", sc_pkcs15_print_id(skey_id));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  398|      0|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  399|      0|		}
  400|      0|		skey_info = (struct sc_pkcs15_skey_info *)skey_obj->data;
  401|       |
  402|      0|		sc_log(ctx, "found secret key '%s'", skey_obj->label);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  403|      0|		data.pin_reference = skey_info->key_reference;
  404|      0|	}
  405|       |
  406|    323|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    646|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (406:7): [True: 0, False: 323]
  ------------------
  407|    323|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|    323|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (407:8): [True: 0, False: 323]
  ------------------
  408|      0|		if (!pincode && !pinlen)
  ------------------
  |  Branch (408:7): [True: 0, False: 0]
  |  Branch (408:19): [True: 0, False: 0]
  ------------------
  409|      0|			data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  410|       |
  411|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN)
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (411:7): [True: 0, False: 0]
  ------------------
  412|      0|			data.pin1.prompt = "Please enter SO PIN";
  413|      0|		else
  414|      0|			data.pin1.prompt = "Please enter PIN";
  415|      0|	}
  416|       |
  417|    323|	if (card->caps & SC_CARD_CAP_SESSION_PIN && sessionpin && sessionpinlen) {
  ------------------
  |  |  563|    646|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
  |  Branch (417:6): [True: 0, False: 323]
  |  Branch (417:46): [True: 0, False: 0]
  |  Branch (417:60): [True: 0, False: 0]
  ------------------
  418|       |		/* session pin is requested and supported with standard verification*/
  419|      0|		data.cmd = SC_PIN_CMD_GET_SESSION_PIN;
  ------------------
  |  |  419|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  420|      0|		memcpy(&data.pin2, &data.pin1, sizeof (data.pin1));
  421|      0|		data.pin2.data = sessionpin;
  422|      0|		data.pin2.len = *sessionpinlen;
  423|    323|	} else {
  424|       |		/* perform a standard verify */
  425|    323|		data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|    323|#define SC_PIN_CMD_VERIFY	0
  ------------------
  426|    323|		if (sessionpinlen)
  ------------------
  |  Branch (426:7): [True: 0, False: 323]
  ------------------
  427|      0|			*sessionpinlen = 0;
  428|    323|	}
  429|       |
  430|    323|	r = sc_lock(card);
  431|    323|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    323|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    323|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    323|	int _ret = (r); \
  |  |  |  |  168|    323|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 323]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    323|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 323]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|       |
  433|       |	/* the path in the pin object is optional */
  434|    323|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (434:6): [True: 54, False: 269]
  |  Branch (434:35): [True: 1, False: 268]
  ------------------
  435|     55|		r = sc_select_file(card, &auth_info->path, NULL);
  436|     55|		if (r)
  ------------------
  |  Branch (436:7): [True: 1, False: 54]
  ------------------
  437|      1|			goto out;
  438|     55|	}
  439|       |
  440|    322|	r = sc_pin_cmd(card, &data);
  441|    322|	auth_info->tries_left = data.pin1.tries_left;
  442|    322|	sc_log(ctx, "PIN cmd result %i", r);
  ------------------
  |  |   71|    322|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  443|    322|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|    322|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:6): [True: 233, False: 89]
  ------------------
  444|    233|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  445|    233|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|    466|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (445:7): [True: 0, False: 233]
  |  Branch (445:49): [True: 0, False: 0]
  ------------------
  446|      0|			*sessionpinlen = data.pin2.len;
  447|      0|		}
  448|    233|	} else {
  449|     89|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  450|     89|				NOTIFY_PIN_BAD);
  451|     89|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|    178|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (451:7): [True: 0, False: 89]
  |  Branch (451:49): [True: 0, False: 0]
  ------------------
  452|      0|			*sessionpinlen = 0;
  453|      0|		}
  454|     89|	}
  455|       |
  456|    322|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN
  ------------------
  |  |   94|    644|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (456:6): [True: 322, False: 0]
  ------------------
  457|    322|			&& auth_info->auth_method != SC_AC_SESSION) {
  ------------------
  |  |  159|    322|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (457:7): [True: 322, False: 0]
  ------------------
  458|    322|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  459|    322|				r == SC_SUCCESS ? NOTIFY_PIN_GOOD : NOTIFY_PIN_BAD);
  ------------------
  |  |   28|    322|#define SC_SUCCESS				0
  ------------------
  |  Branch (459:5): [True: 233, False: 89]
  ------------------
  460|    322|	}
  461|       |
  462|    323|out:
  463|    323|	sc_unlock(card);
  464|    323|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    323|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    323|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    323|	int _ret = r; \
  |  |  |  |  155|    323|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 323, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    323|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 233]
  |  |  |  |  ------------------
  |  |  |  |  157|    323|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    323|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    323|	return _ret; \
  |  |  |  |  163|    323|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|    323|}
sc_pkcs15_free_auth_info:
  735|  5.24k|{
  736|  5.24k|	free(auth_info);
  737|  5.24k|}
sc_pkcs15_pincache_add:
  743|    444|{
  744|    444|	struct sc_context *ctx = p15card->card->ctx;
  745|    444|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  746|    444|	struct sc_pkcs15_object *obj = NULL;
  747|    444|	int r;
  748|       |
  749|    444|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    444|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    444|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    444|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    444|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 444]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  750|       |
  751|    444|	if (!pin || !pinlen)   {
  ------------------
  |  Branch (751:6): [True: 0, False: 444]
  |  Branch (751:14): [True: 0, False: 444]
  ------------------
  752|      0|		sc_log(ctx, "No cache for zero length PIN");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  753|      0|		return;
  754|      0|	}
  755|    444|	else if (!p15card->opts.use_pin_cache)   {
  ------------------
  |  Branch (755:11): [True: 4, False: 440]
  ------------------
  756|      4|		sc_log(ctx, "PIN caching not enabled");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  757|      4|		return;
  758|      4|	}
  759|    440|	else if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    440|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (759:11): [True: 0, False: 440]
  ------------------
  760|      0|		sc_log(ctx, "only 'PIN' auth. object can be cached");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  761|      0|		return;
  762|      0|	}
  763|       |
  764|       |	/* If the PIN protects an object with user consent, don't cache it */
  765|       |
  766|    440|	obj = p15card->obj_list;
  767|  3.19k|	while (obj != NULL) {
  ------------------
  |  Branch (767:9): [True: 2.78k, False: 414]
  ------------------
  768|       |		/* Compare 'sc_pkcs15_object.auth_id' with 'sc_pkcs15_pin_info.auth_id'.
  769|       |		 * In accordance with PKCS#15 "6.1.8 CommonObjectAttributes" and
  770|       |		 * "6.1.16 CommonAuthenticationObjectAttributes" with the exception that
  771|       |		 * "CommonObjectAttributes.accessControlRules" are not taken into account. */
  772|       |
  773|  2.78k|		if (sc_pkcs15_compare_id(&obj->auth_id, &auth_info->auth_id)) {
  ------------------
  |  Branch (773:7): [True: 581, False: 2.20k]
  ------------------
  774|       |			/* Caching is refused, if the protected object requires user consent */
  775|    581|			if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (775:8): [True: 581, False: 0]
  ------------------
  776|    581|				if (obj->user_consent > 0) {
  ------------------
  |  Branch (776:9): [True: 26, False: 555]
  ------------------
  777|     26|					sc_log(ctx, "caching refused (user consent)");
  ------------------
  |  |   71|     26|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  778|     26|					return;
  779|     26|				}
  780|    581|			}
  781|    581|		}
  782|       |
  783|  2.75k|		obj = obj->next;
  784|  2.75k|	}
  785|       |
  786|    414|	r = sc_pkcs15_allocate_object_content(ctx, pin_obj, pin, pinlen);
  787|    414|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|    414|#define SC_SUCCESS				0
  ------------------
  |  Branch (787:6): [True: 0, False: 414]
  ------------------
  788|      0|		sc_log(ctx, "Failed to allocate object content");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  789|      0|		return;
  790|      0|	}
  791|       |
  792|    414|	pin_obj->usage_counter = 0;
  793|    414|	sc_log(ctx, "PIN(%s) cached", pin_obj->label);
  ------------------
  |  |   71|    414|#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|    414|}
sc_pkcs15_pincache_revalidate:
  799|     41|{
  800|     41|	struct sc_context *ctx = p15card->card->ctx;
  801|     41|	sc_pkcs15_object_t *pin_obj;
  802|     41|	int r;
  803|       |
  804|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  805|     41|	if (!p15card->opts.use_pin_cache)
  ------------------
  |  Branch (805:6): [True: 0, False: 41]
  ------------------
  806|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  807|       |
  808|       |	/*  Apps that do not support CK_ALWAYS_AUTHENTICATE
  809|       |	 *  may need pin_cache_ignore_user_consent = 1 */
  810|     41|	if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (810:6): [True: 41, False: 0]
  ------------------
  811|     41|	    if (obj->user_consent)
  ------------------
  |  Branch (811:10): [True: 0, False: 41]
  ------------------
  812|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  813|     41|	}
  814|       |
  815|     41|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|     82|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (815:7): [True: 0, False: 41]
  ------------------
  816|     41|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH))
  ------------------
  |  |  560|     41|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (816:8): [True: 0, False: 41]
  ------------------
  817|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  818|       |
  819|     41|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &obj->auth_id, &pin_obj);
  820|     41|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     41|#define SC_SUCCESS				0
  ------------------
  |  Branch (820:6): [True: 1, False: 40]
  ------------------
  821|      1|		sc_log(ctx, "Could not find pin object for auth_id %s", sc_pkcs15_print_id(&obj->auth_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__
  |  |  ------------------
  ------------------
  822|      1|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      1|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  823|      1|	}
  824|       |
  825|     40|	if (pin_obj->usage_counter >= p15card->opts.pin_cache_counter) {
  ------------------
  |  Branch (825:6): [True: 0, False: 40]
  ------------------
  826|      0|		sc_pkcs15_free_object_content(pin_obj);
  827|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  828|      0|	}
  829|       |
  830|     40|	if (!pin_obj->content.value || !pin_obj->content.len)
  ------------------
  |  Branch (830:6): [True: 11, False: 29]
  |  Branch (830:33): [True: 0, False: 29]
  ------------------
  831|     11|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     11|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  832|       |
  833|     29|	pin_obj->usage_counter++;
  834|     29|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pin_obj->content.value, pin_obj->content.len);
  835|     29|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     29|#define SC_SUCCESS				0
  ------------------
  |  Branch (835:6): [True: 7, False: 22]
  ------------------
  836|       |		/* Ensure that wrong PIN isn't used again */
  837|      7|		sc_pkcs15_free_object_content(pin_obj);
  838|       |
  839|      7|		sc_log(ctx, "Verify PIN error %i", r);
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  840|      7|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      7|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  841|      7|	}
  842|       |
  843|     22|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     22|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     22|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     22|	int _ret = r; \
  |  |  |  |  155|     22|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     22|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  157|     22|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     22|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     22|	return _ret; \
  |  |  |  |  163|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  844|     22|}
sc_pkcs15_pincache_clear:
  847|  4.21k|{
  848|  4.21k|	struct sc_pkcs15_object *objs[32];
  849|  4.21k|	int i, r;
  850|       |
  851|  4.21k|	LOG_FUNC_CALLED(p15card->card->ctx);
  ------------------
  |  |  151|  4.21k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.21k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.21k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.21k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.21k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  852|  4.21k|	r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
  ------------------
  |  |  445|  4.21k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  853|  8.88k|	for (i = 0; i < r; i++)
  ------------------
  |  Branch (853:14): [True: 4.66k, False: 4.21k]
  ------------------
  854|  4.66k|		sc_pkcs15_free_object_content(objs[i]);
  855|  4.21k|}
pkcs15-pin.c:_validate_pin:
  261|    461|{
  262|    461|	size_t max_length;
  263|    461|	if (p15card == NULL) {
  ------------------
  |  Branch (263:6): [True: 0, False: 461]
  ------------------
  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|    461|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    461|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (268:6): [True: 0, False: 461]
  ------------------
  269|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  270|       |
  271|       |	/* prevent buffer overflow from hostile card */
  272|    461|	if (auth_info->attrs.pin.stored_length > SC_MAX_PIN_SIZE)
  ------------------
  |  |   40|    461|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (272:6): [True: 0, False: 461]
  ------------------
  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|    461|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    922|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (276:7): [True: 0, False: 461]
  ------------------
  277|    461|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    461|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (277:8): [True: 0, False: 461]
  ------------------
  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|    461|	max_length = auth_info->attrs.pin.max_length != 0 ? auth_info->attrs.pin.max_length : SC_MAX_PIN_SIZE;
  ------------------
  |  |   40|    480|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (282:15): [True: 442, False: 19]
  ------------------
  283|    461|	if (pinlen > max_length || pinlen < auth_info->attrs.pin.min_length)
  ------------------
  |  Branch (283:6): [True: 9, False: 452]
  |  Branch (283:29): [True: 158, False: 294]
  ------------------
  284|    167|		return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|    167|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  285|       |
  286|    294|	return SC_SUCCESS;
  ------------------
  |  |   28|    294|#define SC_SUCCESS				0
  ------------------
  287|    461|}

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

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

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

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

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

sc_pkcs15_decipher:
  283|    300|{
  284|    300|	sc_context_t *ctx = p15card->card->ctx;
  285|    300|	int r;
  286|    300|	sc_algorithm_info_t *alg_info = NULL;
  287|    300|	sc_security_env_t senv;
  288|    300|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  289|    300|	unsigned long pad_flags = 0, sec_flags = 0;
  290|       |
  291|    300|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    300|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    300|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    300|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    300|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 300]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|       |
  293|    300|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  306|    300|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|    300|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (293:6): [True: 0, False: 300]
  ------------------
  294|    300|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for decryption");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %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|       |
  296|    300|	r = format_senv(p15card, obj, &senv, &alg_info);
  297|    300|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|    300|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    300|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    300|	int _ret = (r); \
  |  |  |  |  168|    300|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 31, False: 269]
  |  |  |  |  ------------------
  |  |  |  |  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|    300|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 269]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  298|    269|	senv.operation = SC_SEC_OPERATION_DECIPHER;
  ------------------
  |  |   47|    269|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  299|       |
  300|    269|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  301|    269|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|    269|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    269|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    269|	int _ret = (r); \
  |  |  |  |  168|    269|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 264]
  |  |  |  |  ------------------
  |  |  |  |  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|    269|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 264]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|    264|	senv.algorithm_flags = sec_flags;
  303|       |
  304|    264|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  305|    264|			outlen);
  306|    264|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|    264|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    264|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    264|	int _ret = (r); \
  |  |  |  |  168|    264|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 142, False: 122]
  |  |  |  |  ------------------
  |  |  |  |  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|    264|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 122]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Strip any padding */
  309|    122|	if (pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) {
  ------------------
  |  |  110|    122|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (309:6): [True: 73, False: 49]
  ------------------
  310|     73|		unsigned int s = r;
  311|     73|		unsigned int key_size = (unsigned int)alg_info->key_length;
  312|     73|		r = sc_pkcs1_strip_02_padding_constant_time(ctx, key_size / 8, out, s, out, &s);
  313|       |		/* for keeping PKCS#1 v1.5 depadding constant-time, do not log error here */
  314|     73|	}
  315|     49|#ifdef ENABLE_OPENSSL
  316|     49|	else if (pad_flags & SC_ALGORITHM_RSA_PAD_OAEP) {
  ------------------
  |  |  108|     49|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (316:11): [True: 0, False: 49]
  ------------------
  317|      0|		size_t s = r;
  318|      0|		uint8_t *param = NULL;
  319|      0|		size_t paramlen = 0;
  320|      0|		if (pMechanism != NULL) {
  ------------------
  |  Branch (320:7): [True: 0, False: 0]
  ------------------
  321|      0|			CK_MECHANISM *mech = (CK_MECHANISM *)pMechanism;
  322|      0|			if (mech->pParameter && sizeof(CK_RSA_PKCS_OAEP_PARAMS) == mech->ulParameterLen) {
  ------------------
  |  Branch (322:8): [True: 0, False: 0]
  |  Branch (322:28): [True: 0, False: 0]
  ------------------
  323|      0|				CK_RSA_PKCS_OAEP_PARAMS * oaep_params = mech->pParameter;
  324|      0|				if (oaep_params->source == CKZ_DATA_SPECIFIED) {
  ------------------
  |  | 1227|      0|#define CKZ_DATA_SPECIFIED 0x00000001UL
  ------------------
  |  Branch (324:9): [True: 0, False: 0]
  ------------------
  325|      0|					param = oaep_params->pSourceData;
  326|      0|					paramlen = (size_t)oaep_params->ulSourceDataLen;
  327|      0|				}
  328|      0|			}
  329|      0|		}
  330|      0|		r = sc_pkcs1_strip_oaep_padding(ctx, out, s, flags, param, paramlen);
  331|      0|		LOG_TEST_RET(ctx, r, "Invalid OAEP padding");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  332|      0|	}
  333|    122|#endif
  334|       |	/* do not log error code to prevent side channel attack */
  335|    122|	return r;
  336|    122|}
sc_pkcs15_compute_signature:
  597|    200|{
  598|    200|	sc_context_t *ctx = p15card->card->ctx;
  599|    200|	int r;
  600|    200|	sc_security_env_t senv;
  601|    200|	sc_algorithm_info_t *alg_info;
  602|    200|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  603|    200|	u8 *buf = NULL, *tmp;
  604|    200|	size_t modlen = 0, buflen = 0;
  605|    200|	unsigned long pad_flags = 0, sec_flags = 0;
  606|       |
  607|    200|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    200|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    200|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    200|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    200|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 200]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|       |
  609|    200|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  307|    200|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  308|    200|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  |  Branch (609:6): [True: 0, False: 200]
  ------------------
  610|    200|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)))
  ------------------
  |  |  314|    200|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  611|    200|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for signing");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|       |
  613|    200|	r = format_senv(p15card, obj, &senv, &alg_info);
  614|    200|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|    200|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    200|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    200|	int _ret = (r); \
  |  |  |  |  168|    200|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 196]
  |  |  |  |  ------------------
  |  |  |  |  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|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 196]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|    196|	senv.operation = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   48|    196|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  616|       |
  617|    196|	switch (obj->type) {
  618|    168|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|    168|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (618:3): [True: 168, False: 28]
  ------------------
  619|    168|			modlen = BYTES4BITS(prkey->modulus_length);
  ------------------
  |  |  146|    168|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  620|    168|			break;
  621|      0|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (621:3): [True: 0, False: 196]
  ------------------
  622|      0|			modlen = BYTES4BITS(prkey->modulus_length) * 2;
  ------------------
  |  |  146|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  623|      0|			break;
  624|     28|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     28|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (624:3): [True: 28, False: 168]
  ------------------
  625|     28|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|     28|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (625:3): [True: 0, False: 196]
  ------------------
  626|     28|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|     28|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (626:3): [True: 0, False: 196]
  ------------------
  627|     28|			modlen = BYTES4BITS(prkey->field_length) * 2;  /* 2*nLen */
  ------------------
  |  |  146|     28|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  628|     28|			break;
  629|      0|		default:
  ------------------
  |  Branch (629:3): [True: 0, False: 196]
  ------------------
  630|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|    196|	}
  632|       |
  633|       |	/* Probably never happens, but better make sure */
  634|    196|	if (outlen < modlen)
  ------------------
  |  Branch (634:6): [True: 1, False: 195]
  ------------------
  635|    196|		LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|    195|	buflen = inlen + modlen;
  638|    195|	buf = sc_mem_secure_alloc(buflen);
  639|    195|	if (buf == NULL)
  ------------------
  |  Branch (639:6): [True: 0, False: 195]
  ------------------
  640|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  641|    195|	memcpy(buf, in, inlen);
  642|       |
  643|       |	/* revert data to sign when signing with the GOST key.
  644|       |	 * TODO: can it be confirmed by the GOST standard?
  645|       |	 * TODO: tested with RuTokenECP, has to be validated for RuToken. */
  646|    195|	if (obj->type == SC_PKCS15_TYPE_PRKEY_GOSTR3410) {
  ------------------
  |  |  420|    195|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (646:6): [True: 0, False: 195]
  ------------------
  647|      0|		r = sc_mem_reverse(buf, inlen);
  648|      0|		LOG_TEST_GOTO_ERR(ctx, r, "Reverse memory error");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  649|      0|	}
  650|       |
  651|    195|	tmp = buf;
  652|       |
  653|       |	/* flags: the requested algo
  654|       |	 * algo_info->flags: what is supported by the card
  655|       |	 * senv.algorithm_flags: what the card will have to do */
  656|       |
  657|       |	/* if the card has SC_ALGORITHM_NEED_USAGE set, and the
  658|       |	 * key is for signing and decryption, we need to emulate signing */
  659|       |
  660|    195|	sc_log(ctx, "supported algorithm flags 0x%lX, private key usage 0x%X", alg_info->flags, prkey->usage);
  ------------------
  |  |   71|    195|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  661|    195|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|    195|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (661:6): [True: 167, False: 28]
  ------------------
  662|    167|		if ((alg_info->flags & SC_ALGORITHM_NEED_USAGE) &&
  ------------------
  |  |   95|    167|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  |  Branch (662:7): [True: 0, False: 167]
  ------------------
  663|      0|			((prkey->usage & USAGE_ANY_SIGN) &&
  ------------------
  |  |  588|      0|#define USAGE_ANY_SIGN          (SC_PKCS15_PRKEY_USAGE_SIGN|\
  |  |  ------------------
  |  |  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  |  |  ------------------
  |  |  589|      0|                                 SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)
  |  |  ------------------
  |  |  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  |  |  ------------------
  ------------------
  |  Branch (663:5): [True: 0, False: 0]
  ------------------
  664|      0|			(prkey->usage & USAGE_ANY_DECIPHER)) ) {
  ------------------
  |  |  590|      0|#define USAGE_ANY_DECIPHER      (SC_PKCS15_PRKEY_USAGE_DECRYPT|\
  |  |  ------------------
  |  |  |  |  306|      0|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |  591|      0|                                 SC_PKCS15_PRKEY_USAGE_UNWRAP)
  |  |  ------------------
  |  |  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
  |  Branch (664:4): [True: 0, False: 0]
  ------------------
  665|      0|			size_t tmplen = buflen;
  666|      0|			if (flags & SC_ALGORITHM_RSA_RAW) {
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (666:8): [True: 0, False: 0]
  ------------------
  667|      0|				r = sc_pkcs15_decipher(p15card, obj, flags, in, inlen, out, outlen, NULL);
  668|      0|				goto err;
  669|      0|			}
  670|      0|			if (modlen > tmplen)
  ------------------
  |  Branch (670:8): [True: 0, False: 0]
  ------------------
  671|      0|				LOG_TEST_GOTO_ERR(ctx, SC_ERROR_NOT_ALLOWED, "Buffer too small, needs recompile!");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|       |
  673|       |			/* XXX Assuming RSA key here */
  674|      0|			r = sc_pkcs1_encode(ctx, flags, in, inlen, buf, &tmplen, prkey->modulus_length, pMechanism);
  675|       |
  676|       |			/* no padding needed - already done */
  677|      0|			flags &= ~SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|      0|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  678|       |			/* instead use raw rsa */
  679|      0|			flags |= SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  680|       |
  681|      0|			LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  682|       |
  683|      0|			r = sc_pkcs15_decipher(p15card, obj, flags, buf, modlen, out, outlen, NULL);
  684|      0|			goto err;
  685|      0|		}
  686|       |
  687|       |
  688|       |		/* If the card doesn't support the requested algorithm, we normally add the
  689|       |		 * padding here in software and ask the card to do a raw signature.  There's
  690|       |		 * one exception to that, where we might be able to get the signature to
  691|       |		 * succeed by stripping padding if the card only offers higher-level
  692|       |		 * signature operations.  The only thing we can strip is the DigestInfo
  693|       |		 * block from PKCS1 padding. */
  694|    167|		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  109|    167|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
              		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  133|    167|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (694:7): [True: 0, False: 167]
  ------------------
  695|      0|			!(alg_info->flags & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (695:4): [True: 0, False: 0]
  ------------------
  696|      0|			!(alg_info->flags & SC_ALGORITHM_RSA_HASH_NONE) &&
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (696:4): [True: 0, False: 0]
  ------------------
  697|      0|			(alg_info->flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)) {
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (697:4): [True: 0, False: 0]
  ------------------
  698|      0|			unsigned int algo;
  699|      0|			size_t tmplen = buflen;
  700|       |
  701|      0|			r = sc_pkcs1_strip_digest_info_prefix(&algo, tmp, inlen, tmp, &tmplen);
  702|      0|			if (r != SC_SUCCESS || algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
              			if (r != SC_SUCCESS || algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (702:8): [True: 0, False: 0]
  |  Branch (702:27): [True: 0, False: 0]
  ------------------
  703|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  704|      0|				goto err;
  705|      0|			}
  706|      0|			flags &= ~SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  707|      0|			flags |= algo;
  708|      0|			inlen = tmplen;
  709|      0|		}
  710|    167|	}
  711|       |
  712|       |
  713|       |	/* ECDSA software hash has already been done, or is not needed, or card will do hash */
  714|       |	/* if card can not do the hash, will use SC_ALGORITHM_ECDSA_RAW */
  715|    195|	if (obj->type == SC_PKCS15_TYPE_PRKEY_EC) {
  ------------------
  |  |  421|    195|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (715:6): [True: 28, False: 167]
  ------------------
  716|     28|		if ((alg_info->flags & SC_ALGORITHM_ECDSA_RAW)
  ------------------
  |  |  174|     28|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (716:7): [True: 28, False: 0]
  ------------------
  717|     28|				&& !(flags & SC_ALGORITHM_ECDSA_HASHES & alg_info->flags)) {
  ------------------
  |  |  181|     28|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     28|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     28|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     28|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     28|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     28|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     28|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     28|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     28|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     28|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (717:8): [True: 28, False: 0]
  ------------------
  718|     28|			sc_log(ctx, "ECDSA using SC_ALGORITHM_ECDSA_RAW flags before 0x%8.8lx", flags);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  719|     28|				flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|     28|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  720|     28|				flags &= ~SC_ALGORITHM_ECDSA_HASHES;
  ------------------
  |  |  181|     28|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     28|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     28|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     28|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     28|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     28|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     28|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     28|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     28|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     28|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     28|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  721|     28|		}
  722|     28|	}
  723|       |
  724|    195|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  725|    195|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    195|#define SC_SUCCESS				0
  ------------------
  |  Branch (725:6): [True: 2, False: 193]
  ------------------
  726|      2|		goto err;
  727|      2|	}
  728|       |	/* senv now has flags card or driver will do */
  729|    193|	senv.algorithm_flags = sec_flags;
  730|       |
  731|    193|	sc_log(ctx, "DEE flags:0x%8.8lx alg_info->flags:0x%8.8lx pad:0x%8.8lx sec:0x%8.8lx",
  ------------------
  |  |   71|    193|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  732|    193|		flags, alg_info->flags, pad_flags, sec_flags);
  733|       |
  734|       |	/* add the padding bytes (if necessary) */
  735|    193|	if (pad_flags != 0) {
  ------------------
  |  Branch (735:6): [True: 82, False: 111]
  ------------------
  736|     82|		size_t tmplen = buflen;
  737|       |
  738|       |		/* XXX Assuming RSA key here */
  739|     82|		r = sc_pkcs1_encode(ctx, pad_flags, tmp, inlen, tmp, &tmplen,
  740|     82|		    prkey->modulus_length, pMechanism);
  741|     82|		LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|     82|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     82|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     82|	int _ret = (r); \
  |  |  |  |  178|     82|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 11, False: 71]
  |  |  |  |  ------------------
  |  |  |  |  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|     82|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|     71|		inlen = tmplen;
  743|     71|	}
  744|    111|	else if ( senv.algorithm == SC_ALGORITHM_RSA &&
  ------------------
  |  |   69|    222|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (744:12): [True: 84, False: 27]
  ------------------
  745|     84|	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  103|     84|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
              	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  104|     84|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (745:12): [True: 0, False: 84]
  ------------------
  746|       |		/* Add zero-padding if input is shorter than the modulus */
  747|      0|		if (inlen < modlen) {
  ------------------
  |  Branch (747:7): [True: 0, False: 0]
  ------------------
  748|      0|			if (modlen > buflen) {
  ------------------
  |  Branch (748:8): [True: 0, False: 0]
  ------------------
  749|      0|				r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  750|      0|				goto err;
  751|      0|			}
  752|      0|			memmove(tmp+modlen-inlen, tmp, inlen);
  753|      0|			memset(tmp, 0, modlen-inlen);
  754|      0|		}
  755|      0|		inlen = modlen;
  756|      0|	}
  757|       |	/* PKCS#11 MECHANISMS V2.30: 6.3.1 EC Signatures
  758|       |	 * If the length of the hash value is larger than the bit length of n, only
  759|       |	 * the leftmost bits of the hash up to the length of n will be used. Any
  760|       |	 * truncation is done by the token.
  761|       |	 * But if card is going to do the hash, pass in all the data
  762|       |	 */
  763|    111|	else if (senv.algorithm == SC_ALGORITHM_EC &&
  ------------------
  |  |   70|    222|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (763:11): [True: 27, False: 84]
  ------------------
  764|     27|			(senv.algorithm_flags & SC_ALGORITHM_ECDSA_HASHES) == 0) {
  ------------------
  |  |  181|     27|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|     27|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|     27|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|     27|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|     27|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|     27|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|     27|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|     27|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|     27|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|     27|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|     27|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|     27|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|     27|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|     27|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|     27|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (764:4): [True: 27, False: 0]
  ------------------
  765|     27|		inlen = MIN(inlen, BYTES4BITS(prkey->field_length));
  ------------------
  |  |   70|     27|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 16, False: 11]
  |  |  ------------------
  ------------------
  766|     27|	}
  767|       |
  768|       |
  769|    182|	r = use_key(p15card, obj, &senv, sc_compute_signature, tmp, inlen,
  770|    182|			out, outlen);
  771|    182|	LOG_TEST_GOTO_ERR(ctx, r, "use_key() failed");
  ------------------
  |  |  184|    182|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    182|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    182|	int _ret = (r); \
  |  |  |  |  178|    182|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 132, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  179|    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
  |  |  |  |  ------------------
  |  |  |  |  180|    132|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    132|		goto err; \
  |  |  |  |  182|    132|	} \
  |  |  |  |  183|    182|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 50]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  772|       |
  773|       |	/* Some cards may return RSA signature as integer without leading zero bytes */
  774|       |	/* Already know outlen >= modlen and r >= 0 */
  775|     50|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA && (unsigned)r < modlen) {
  ------------------
  |  |  419|    100|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (775:6): [True: 50, False: 0]
  |  Branch (775:47): [True: 44, False: 6]
  ------------------
  776|     44|		memmove(out + modlen - r, out, r);
  777|     44|		memset(out, 0, modlen - r);
  778|     44|		r = (int)modlen;
  779|     44|	}
  780|       |
  781|    195|err:
  782|    195|	sc_mem_secure_clear_free(buf, buflen);
  ------------------
  |  | 1580|    195|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|    195|	sc_mem_clear(ptr, len); \
  |  | 1582|    195|	sc_mem_secure_free(ptr, len); \
  |  | 1583|    195|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 195]
  |  |  ------------------
  ------------------
  783|       |
  784|    195|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    195|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    195|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    195|	int _ret = r; \
  |  |  |  |  155|    195|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 145, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  156|    145|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    145|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 145, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    145|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    145|	} else { \
  |  |  |  |  159|     50|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     50|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     50|	} \
  |  |  |  |  162|    195|	return _ret; \
  |  |  |  |  163|    195|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|    195|}
pkcs15-sec.c:format_senv:
  175|    500|{
  176|    500|	sc_context_t *ctx = p15card->card->ctx;
  177|    500|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  178|    500|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
  179|       |
  180|    500|	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|    500|	memcpy(senv_out->supported_algos, &p15card->tokeninfo->supported_algos, sizeof(senv_out->supported_algos));
  185|       |
  186|    500|	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  416|    500|#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|  1.00k|#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|      0|#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|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (186:8): [True: 500, False: 0]
  |  Branch (186:75): [True: 0, False: 0]
  ------------------
  187|    500|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This is not a private or secret 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* If the key is not native, we can't operate with it. */
  190|    500|	if (!prkey->native)
  ------------------
  |  Branch (190:6): [True: 0, False: 500]
  ------------------
  191|    500|		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|    500|	switch (obj->type) {
  194|    449|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|    449|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (194:3): [True: 449, False: 51]
  ------------------
  195|    449|			*alg_info_out = sc_card_find_rsa_alg(p15card->card, prkey->modulus_length);
  196|    449|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (196:8): [True: 12, False: 437]
  ------------------
  197|     12|				sc_log(ctx, "Card does not support RSA with key length %zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  198|     12|						prkey->modulus_length);
  199|     12|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|     12|			}
  201|    437|			senv_out->algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|    437|#define SC_ALGORITHM_RSA		0
  ------------------
  202|    437|			senv_out->key_size_bits = prkey->modulus_length;
  203|    437|			break;
  204|       |
  205|      7|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      7|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (205:3): [True: 7, False: 493]
  ------------------
  206|      7|			*alg_info_out = sc_card_find_gostr3410_alg(p15card->card, prkey->modulus_length);
  207|      7|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (207:8): [True: 7, False: 0]
  ------------------
  208|      7|				sc_log(ctx, "Card does not support GOSTR3410 with key length %zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  209|      7|						prkey->modulus_length);
  210|      7|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  211|      7|			}
  212|      0|			senv_out->algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   71|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  213|      0|			senv_out->key_size_bits = prkey->modulus_length;
  214|      0|			break;
  215|       |
  216|      0|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|      0|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (216:3): [True: 0, False: 500]
  ------------------
  217|      0|			*alg_info_out = sc_card_find_eddsa_alg(p15card->card, prkey->field_length, NULL);
  218|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (218:8): [True: 0, False: 0]
  ------------------
  219|      0|				sc_log(ctx, "Card does not support EDDSA with field_size %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  220|      0|						prkey->field_length);
  221|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      0|			}
  223|      0|			senv_out->algorithm = SC_ALGORITHM_EDDSA;
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  224|      0|			senv_out->key_size_bits = prkey->field_length;
  225|      0|			break;
  226|       |
  227|      0|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|      0|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (227:3): [True: 0, False: 500]
  ------------------
  228|      0|			*alg_info_out = sc_card_find_xeddsa_alg(p15card->card, prkey->field_length, NULL);
  229|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (229:8): [True: 0, False: 0]
  ------------------
  230|      0|				sc_log(ctx, "Card does not support XEDDSA with field_size %zu",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  231|      0|						prkey->field_length);
  232|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|      0|			}
  234|      0|			senv_out->algorithm = SC_ALGORITHM_XEDDSA;
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  235|      0|			senv_out->key_size_bits = prkey->field_length;
  236|      0|			break;
  237|       |
  238|     44|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|     44|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (238:3): [True: 44, False: 456]
  ------------------
  239|     44|			*alg_info_out = sc_card_find_ec_alg(p15card->card, prkey->field_length, NULL);
  240|     44|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (240:8): [True: 16, False: 28]
  ------------------
  241|     16|				sc_log(ctx, "Card does not support EC with field_size %zu",
  ------------------
  |  |   71|     16|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  242|     16|						prkey->field_length);
  243|     16|				LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|     16|			}
  245|     28|			senv_out->algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|     28|#define SC_ALGORITHM_EC		2
  ------------------
  246|     28|			senv_out->key_size_bits = prkey->field_length;
  247|       |
  248|     28|			senv_out->flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   56|     28|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  249|     28|			senv_out->algorithm_ref = prkey->field_length;
  250|     28|			break;
  251|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (251:3): [True: 0, False: 500]
  ------------------
  252|      0|			if (skey->key_type != CKK_AES)
  ------------------
  |  |  485|      0|#define CKK_AES 0x0000001FUL
  ------------------
  |  Branch (252:8): [True: 0, False: 0]
  ------------------
  253|      0|				LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|      0|			*alg_info_out = sc_card_find_alg(p15card->card, SC_ALGORITHM_AES,
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  255|      0|					skey->value_len, NULL);
  256|      0|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (256:8): [True: 0, False: 0]
  ------------------
  257|      0|				sc_log(ctx, "Card does not support AES with key length %zu", skey->value_len);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  258|      0|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|      0|			}
  260|      0|			senv_out->algorithm = SC_ALGORITHM_AES;
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  261|      0|			senv_out->key_size_bits = skey->value_len;
  262|      0|			break;
  263|       |			/* add other crypto types here */
  264|      0|		default:
  ------------------
  |  Branch (264:3): [True: 0, False: 500]
  ------------------
  265|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|    500|	}
  267|    465|	senv_out->flags |= SC_SEC_ENV_ALG_PRESENT;
  ------------------
  |  |   60|    465|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  268|       |
  269|       |	/* optional keyReference attribute (the default value is -1) */
  270|    465|	if (prkey->key_reference >= 0) {
  ------------------
  |  Branch (270:6): [True: 463, False: 2]
  ------------------
  271|    463|		senv_out->key_ref_len = 1;
  272|    463|		senv_out->key_ref[0] = prkey->key_reference & 0xFF;
  273|    463|		senv_out->flags |= SC_SEC_ENV_KEY_REF_PRESENT;
  ------------------
  |  |   58|    463|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  274|    463|	}
  275|       |
  276|    465|	return SC_SUCCESS;
  ------------------
  |  |   28|    465|#define SC_SUCCESS				0
  ------------------
  277|    500|}
pkcs15-sec.c:use_key:
  133|    446|{
  134|    446|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    446|#define SC_SUCCESS				0
  ------------------
  135|    446|	int revalidated_cached_pin = 0;
  136|    446|	sc_path_t path;
  137|    446|	LOG_TEST_RET(p15card->card->ctx, get_file_path(obj, &path), "Failed to get key file path.");
  ------------------
  |  |  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: 0, False: 446]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    446|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 446]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|       |
  139|    446|	r = sc_lock(p15card->card);
  140|    446|	LOG_TEST_RET(p15card->card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  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: 0, False: 446]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    446|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 446]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|       |
  142|    468|	do {
  143|    468|		if (path.len != 0 || path.aid.len != 0) {
  ------------------
  |  Branch (143:7): [True: 24, False: 444]
  |  Branch (143:24): [True: 37, False: 407]
  ------------------
  144|     61|			r = select_key_file(p15card, obj, senv);
  145|     61|			if (r < 0) {
  ------------------
  |  Branch (145:8): [True: 6, False: 55]
  ------------------
  146|      6|				sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      6|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  147|      6|						"Unable to select private key file");
  148|      6|			}
  149|     61|		}
  150|    468|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|    468|#define SC_SUCCESS				0
  ------------------
  |  Branch (150:7): [True: 462, False: 6]
  ------------------
  151|    462|			r = sc_set_security_env(p15card->card, senv, 0);
  152|       |
  153|    468|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|    468|#define SC_SUCCESS				0
  ------------------
  |  Branch (153:7): [True: 370, False: 98]
  ------------------
  154|    370|			r = card_command(p15card->card, in, inlen, out, outlen);
  155|       |
  156|    468|		if (revalidated_cached_pin)
  ------------------
  |  Branch (156:7): [True: 22, False: 446]
  ------------------
  157|       |			/* only re-validate once */
  158|     22|			break;
  159|    446|		if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|    446|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (159:7): [True: 41, False: 405]
  ------------------
  160|     41|			r = sc_pkcs15_pincache_revalidate(p15card, obj);
  161|     41|			if (r < 0)
  ------------------
  |  Branch (161:8): [True: 19, False: 22]
  ------------------
  162|     19|				break;
  163|     22|			revalidated_cached_pin = 1;
  164|     22|		}
  165|    446|	} while (revalidated_cached_pin);
  ------------------
  |  Branch (165:11): [True: 22, False: 405]
  ------------------
  166|       |
  167|    446|	sc_unlock(p15card->card);
  168|       |
  169|    446|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|    446|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    446|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    446|	int _ret = r; \
  |  |  |  |  155|    446|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 323, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  156|    323|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    274|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 274, False: 49]
  |  |  |  |  ------------------
  |  |  |  |  157|    323|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    323|	} else { \
  |  |  |  |  159|    123|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    123|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    123|	} \
  |  |  |  |  162|    446|	return _ret; \
  |  |  |  |  163|    446|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|    446|}
pkcs15-sec.c:get_file_path:
   57|    507|{
   58|    507|	if (!path)
  ------------------
  |  Branch (58:6): [True: 0, False: 507]
  ------------------
   59|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   60|       |
   61|    507|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
   62|    507|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
   63|       |
   64|    507|	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  416|    507|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  418|    507|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (64:6): [True: 507, False: 0]
  ------------------
   65|    507|		*path = prkey->path;
   66|    507|	}
   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|    507|	return SC_SUCCESS;
  ------------------
  |  |   28|    507|#define SC_SUCCESS				0
  ------------------
   74|    507|}
pkcs15-sec.c:select_key_file:
   80|     61|{
   81|     61|	sc_context_t *ctx = p15card->card->ctx;
   82|     61|	sc_path_t orig_path;
   83|     61|	sc_path_t path, file_id;
   84|     61|	int r;
   85|       |
   86|     61|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     61|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     61|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     61|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     61|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   87|       |
   88|     61|	LOG_TEST_RET(ctx, get_file_path(key, &orig_path), "Could not get key file path.");
  ------------------
  |  |  174|     61|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     61|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     61|	int _ret = (r); \
  |  |  |  |  168|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 61]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|     61|	memset(&path, 0, sizeof(sc_path_t));
   90|     61|	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|     61|	if (!orig_path.len && orig_path.aid.len) {
  ------------------
  |  Branch (96:6): [True: 37, False: 24]
  |  Branch (96:24): [True: 37, False: 0]
  ------------------
   97|       |		/* Private key is a SDO allocated in application DF */
   98|     37|		path = orig_path;
   99|     37|	}
  100|     24|	else if (orig_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (100:11): [True: 0, False: 24]
  |  Branch (100:33): [True: 0, False: 0]
  ------------------
  101|       |		/* Path is relative to app. DF */
  102|      0|		path = p15card->file_app->path;
  103|      0|		file_id = orig_path;
  104|      0|		sc_append_path(&path, &file_id);
  105|      0|		senv->file_ref = file_id;
  106|      0|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|      0|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  107|      0|	}
  108|     24|	else if (orig_path.len > 2) {
  ------------------
  |  Branch (108:11): [True: 24, False: 0]
  ------------------
  109|     24|		path = orig_path;
  110|     24|		memcpy(file_id.value, orig_path.value + orig_path.len - 2, 2);
  111|     24|		file_id.len = 2;
  112|     24|		file_id.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     24|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  113|     24|		senv->file_ref = file_id;
  114|     24|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|     24|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  115|     24|	}
  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|     61|	r = sc_select_file(p15card->card, &path, NULL);
  121|     61|	LOG_TEST_RET(ctx, r, "sc_select_file() 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: 6, False: 55]
  |  |  |  |  ------------------
  |  |  |  |  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|     61|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 55]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|     55|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|     55|}

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

sc_pkcs15emu_srbeid_init_ex:
  570|  6.94k|{
  571|  6.94k|	(void)aid;
  572|       |
  573|  6.94k|	if (p15card->card->type != SC_CARD_TYPE_SRBEID_BASE)
  ------------------
  |  Branch (573:6): [True: 6.94k, False: 0]
  ------------------
  574|  6.94k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.94k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  575|       |
  576|      0|	return sc_pkcs15emu_srbeid_init(p15card);
  577|  6.94k|}

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

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

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

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

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

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

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

sc_get_version:
   59|  14.1k|{
   60|  14.1k|    return sc_version;
   61|  14.1k|}
sc_hex_to_bin:
   64|   293k|{
   65|   293k|	const char *sc_hex_to_bin_separators = " :";
   66|   293k|	if (in == NULL || out == NULL || outlen == NULL) {
  ------------------
  |  Branch (66:6): [True: 56, False: 293k]
  |  Branch (66:20): [True: 0, False: 293k]
  |  Branch (66:35): [True: 0, False: 293k]
  ------------------
   67|     56|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     56|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   68|     56|	}
   69|       |
   70|   293k|	int byte_needs_nibble = 0;
   71|   293k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   293k|#define SC_SUCCESS				0
  ------------------
   72|   293k|	size_t left = *outlen;
   73|   293k|	u8 byte = 0;
   74|  4.87M|	while (*in != '\0' && 0 != left) {
  ------------------
  |  Branch (74:9): [True: 4.57M, False: 293k]
  |  Branch (74:24): [True: 4.57M, False: 17]
  ------------------
   75|  4.57M|		char c = *in++;
   76|  4.57M|		u8 nibble;
   77|  4.57M|		if      ('0' <= c && c <= '9')
  ------------------
  |  Branch (77:12): [True: 4.57M, False: 413]
  |  Branch (77:24): [True: 2.45M, False: 2.12M]
  ------------------
   78|  2.45M|			nibble = c - '0';
   79|  2.12M|		else if ('a' <= c && c <= 'f')
  ------------------
  |  Branch (79:12): [True: 399k, False: 1.72M]
  |  Branch (79:24): [True: 399k, False: 14]
  ------------------
   80|   399k|			nibble = c - 'a' + 10;
   81|  1.72M|		else if ('A' <= c && c <= 'F')
  ------------------
  |  Branch (81:12): [True: 592k, False: 1.13M]
  |  Branch (81:24): [True: 592k, False: 23]
  ------------------
   82|   592k|			nibble = c - 'A' + 10;
   83|  1.13M|		else {
   84|  1.13M|			if (strchr(sc_hex_to_bin_separators, (int) c)) {
  ------------------
  |  Branch (84:8): [True: 1.13M, False: 113]
  ------------------
   85|  1.13M|				if (byte_needs_nibble) {
  ------------------
  |  Branch (85:9): [True: 3, False: 1.13M]
  ------------------
   86|      3|					r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      3|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   87|      3|					goto err;
   88|      3|				}
   89|  1.13M|				continue;
   90|  1.13M|			}
   91|    113|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    113|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|    113|			goto err;
   93|  1.13M|		}
   94|       |
   95|  3.44M|		if (byte_needs_nibble) {
  ------------------
  |  Branch (95:7): [True: 1.71M, False: 1.72M]
  ------------------
   96|  1.71M|			byte |= nibble;
   97|  1.71M|			*out++ = (u8) byte;
   98|  1.71M|			left--;
   99|  1.71M|			byte_needs_nibble = 0;
  100|  1.72M|		} else {
  101|  1.72M|			byte  = nibble << 4;
  102|  1.72M|			byte_needs_nibble = 1;
  103|  1.72M|		}
  104|  3.44M|	}
  105|       |
  106|   293k|	if (left == *outlen && 1 == byte_needs_nibble && 0 != left) {
  ------------------
  |  Branch (106:6): [True: 8.88k, False: 284k]
  |  Branch (106:25): [True: 5.47k, False: 3.41k]
  |  Branch (106:51): [True: 5.47k, False: 0]
  ------------------
  107|       |		/* no output written so far, but we have a valid nibble in the upper
  108|       |		 * bits. Allow this special case. */
  109|  5.47k|		*out = (u8) byte>>4;
  110|  5.47k|		left--;
  111|  5.47k|		byte_needs_nibble = 0;
  112|  5.47k|	}
  113|       |
  114|       |	/* for ease of implementation we only accept completely hexed bytes. */
  115|   293k|	if (byte_needs_nibble) {
  ------------------
  |  Branch (115:6): [True: 7, False: 293k]
  ------------------
  116|      7|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      7|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  117|      7|		goto err;
  118|      7|	}
  119|       |
  120|       |	/* skip all trailing separators to see if we missed something */
  121|   293k|	while (*in != '\0') {
  ------------------
  |  Branch (121:9): [True: 212, False: 293k]
  ------------------
  122|    212|		if (NULL == strchr(sc_hex_to_bin_separators, (int) *in))
  ------------------
  |  Branch (122:7): [True: 10, False: 202]
  ------------------
  123|     10|			break;
  124|    202|		in++;
  125|    202|	}
  126|   293k|	if (*in != '\0') {
  ------------------
  |  Branch (126:6): [True: 10, False: 293k]
  ------------------
  127|     10|		r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     10|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  128|     10|		goto err;
  129|     10|	}
  130|       |
  131|   293k|err:
  132|   293k|	*outlen -= left;
  133|   293k|	return r;
  134|   293k|}
sc_bin_to_hex:
  138|   304k|{
  139|   304k|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (139:6): [True: 0, False: 304k]
  |  Branch (139:20): [True: 0, False: 304k]
  ------------------
  140|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  141|      0|	}
  142|       |
  143|   304k|	if (in_sep > 0) {
  ------------------
  |  Branch (143:6): [True: 301k, False: 2.99k]
  ------------------
  144|   301k|		if (out_len < in_len*3 || out_len < 1)
  ------------------
  |  Branch (144:7): [True: 0, False: 301k]
  |  Branch (144:29): [True: 0, False: 301k]
  ------------------
  145|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  146|   301k|	} else {
  147|  2.99k|		if (out_len < in_len*2 + 1)
  ------------------
  |  Branch (147:7): [True: 1, False: 2.98k]
  ------------------
  148|      1|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      1|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  149|  2.99k|	}
  150|       |
  151|   304k|	const char hex[] = "0123456789abcdef";
  152|  2.90M|	while (in_len) {
  ------------------
  |  Branch (152:9): [True: 2.59M, False: 304k]
  ------------------
  153|  2.59M|		unsigned char value = *in++;
  154|  2.59M|		*out++ = hex[(value >> 4) & 0xF];
  155|  2.59M|		*out++ = hex[ value       & 0xF];
  156|  2.59M|		in_len--;
  157|  2.59M|		if (in_len && in_sep > 0)
  ------------------
  |  Branch (157:7): [True: 2.43M, False: 168k]
  |  Branch (157:17): [True: 2.41M, False: 14.7k]
  ------------------
  158|  2.41M|			*out++ = (char)in_sep;
  159|  2.59M|	}
  160|   304k|	*out = '\0';
  161|       |
  162|   304k|	return SC_SUCCESS;
  ------------------
  |  |   28|   304k|#define SC_SUCCESS				0
  ------------------
  163|   304k|}
ulong2bebytes:
  189|  48.6k|{
  190|  48.6k|	if (buf != NULL) {
  ------------------
  |  Branch (190:6): [True: 48.6k, False: 0]
  ------------------
  191|  48.6k|		buf[3] = (u8) (x & 0xff);
  192|  48.6k|		buf[2] = (u8) ((x >> 8) & 0xff);
  193|  48.6k|		buf[1] = (u8) ((x >> 16) & 0xff);
  194|  48.6k|		buf[0] = (u8) ((x >> 24) & 0xff);
  195|  48.6k|	}
  196|  48.6k|	return buf;
  197|  48.6k|}
bebytes2ulong:
  209|  99.9k|{
  210|  99.9k|	if (buf == NULL)
  ------------------
  |  Branch (210:6): [True: 0, False: 99.9k]
  ------------------
  211|      0|		return 0UL;
  212|  99.9k|	return (unsigned long)buf[0] << 24
  213|  99.9k|		| (unsigned long)buf[1] << 16
  214|  99.9k|		| (unsigned long)buf[2] << 8
  215|  99.9k|		| (unsigned long)buf[3];
  216|  99.9k|}
bebytes2ushort:
  219|   161k|{
  220|   161k|	if (buf == NULL)
  ------------------
  |  Branch (220:6): [True: 0, False: 161k]
  ------------------
  221|      0|		return 0U;
  222|   161k|	return (unsigned short)buf[0] << 8
  223|   161k|		| (unsigned short)buf[1];
  224|   161k|}
lebytes2ushort:
  227|  3.58k|{
  228|  3.58k|	if (buf == NULL)
  ------------------
  |  Branch (228:6): [True: 0, False: 3.58k]
  ------------------
  229|      0|		return 0U;
  230|  3.58k|	return (unsigned short)buf[1] << 8
  231|  3.58k|		| (unsigned short)buf[0];
  232|  3.58k|}
lebytes2ulong:
  235|    940|{
  236|    940|	if (buf == NULL)
  ------------------
  |  Branch (236:6): [True: 0, False: 940]
  ------------------
  237|      0|		return 0UL;
  238|    940|	return (unsigned long)buf[3] << 24
  239|    940|		| (unsigned long)buf[2] << 16
  240|    940|		| (unsigned long)buf[1] << 8
  241|    940|		| (unsigned long)buf[0];
  242|    940|}
set_string:
  245|  12.4k|{
  246|  12.4k|	if (strp == NULL) {
  ------------------
  |  Branch (246:6): [True: 0, False: 12.4k]
  ------------------
  247|      0|		return;
  248|      0|	}
  249|       |
  250|  12.4k|	free(*strp);
  251|  12.4k|	*strp = value ? strdup(value) : NULL;
  ------------------
  |  Branch (251:10): [True: 12.4k, False: 0]
  ------------------
  252|  12.4k|}
sc_init_oid:
  255|  48.3k|{
  256|  48.3k|	int ii;
  257|       |
  258|  48.3k|	if (!oid)
  ------------------
  |  Branch (258:6): [True: 0, False: 48.3k]
  ------------------
  259|      0|		return;
  260|   821k|	for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
  ------------------
  |  |   46|   821k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (260:13): [True: 773k, False: 48.3k]
  ------------------
  261|   773k|		oid->value[ii] = -1;
  262|  48.3k|}
sc_format_oid:
  265|  16.7k|{
  266|  16.7k|	int        ii, ret = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  16.7k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  267|  16.7k|	const char *p;
  268|  16.7k|	char       *q;
  269|       |
  270|  16.7k|	if (oid == NULL || in == NULL)
  ------------------
  |  Branch (270:6): [True: 0, False: 16.7k]
  |  Branch (270:21): [True: 0, False: 16.7k]
  ------------------
  271|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  272|       |
  273|  16.7k|	sc_init_oid(oid);
  274|       |
  275|  16.7k|	p = in;
  276|   141k|	for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++)   {
  ------------------
  |  |   46|   141k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (276:13): [True: 141k, False: 0]
  ------------------
  277|   141k|		oid->value[ii] = (int)strtol(p, &q, 10);
  278|   141k|		if (!*q)
  ------------------
  |  Branch (278:7): [True: 16.7k, False: 124k]
  ------------------
  279|  16.7k|			break;
  280|       |
  281|   124k|		if (!(q[0] == '.' && isdigit((unsigned char)q[1])))
  ------------------
  |  Branch (281:9): [True: 124k, False: 0]
  |  Branch (281:24): [True: 124k, False: 0]
  ------------------
  282|      0|			goto out;
  283|       |
  284|   124k|		p = q + 1;
  285|   124k|	}
  286|       |
  287|  16.7k|	if (!sc_valid_oid(oid))
  ------------------
  |  Branch (287:6): [True: 0, False: 16.7k]
  ------------------
  288|      0|		goto out;
  289|       |
  290|  16.7k|	ret = SC_SUCCESS;
  ------------------
  |  |   28|  16.7k|#define SC_SUCCESS				0
  ------------------
  291|  16.7k|out:
  292|  16.7k|	if (ret)
  ------------------
  |  Branch (292:6): [True: 0, False: 16.7k]
  ------------------
  293|      0|		sc_init_oid(oid);
  294|       |
  295|  16.7k|	return ret;
  296|  16.7k|}
sc_compare_oid:
  299|  32.3k|{
  300|  32.3k|	int i;
  301|       |
  302|  32.3k|	if (oid1 == NULL || oid2 == NULL) {
  ------------------
  |  Branch (302:6): [True: 0, False: 32.3k]
  |  Branch (302:22): [True: 0, False: 32.3k]
  ------------------
  303|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  304|      0|	}
  305|       |
  306|  90.3k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++)   {
  ------------------
  |  |   46|  90.3k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (306:14): [True: 90.3k, False: 0]
  ------------------
  307|  90.3k|		if (oid1->value[i] != oid2->value[i])
  ------------------
  |  Branch (307:7): [True: 27.3k, False: 63.0k]
  ------------------
  308|  27.3k|			return 0;
  309|  63.0k|		if (oid1->value[i] == -1)
  ------------------
  |  Branch (309:7): [True: 5.00k, False: 58.0k]
  ------------------
  310|  5.00k|			break;
  311|  63.0k|	}
  312|       |
  313|  5.00k|	return 1;
  314|  32.3k|}
sc_valid_oid:
  318|  16.9k|{
  319|  16.9k|	int ii;
  320|       |
  321|  16.9k|	if (!oid)
  ------------------
  |  Branch (321:6): [True: 0, False: 16.9k]
  ------------------
  322|      0|		return 0;
  323|  16.9k|	if (oid->value[0] == -1 || oid->value[1] == -1)
  ------------------
  |  Branch (323:6): [True: 2, False: 16.9k]
  |  Branch (323:29): [True: 0, False: 16.9k]
  ------------------
  324|      2|		return 0;
  325|  16.9k|	if (oid->value[0] > 2 || oid->value[1] > 39)
  ------------------
  |  Branch (325:6): [True: 0, False: 16.9k]
  |  Branch (325:27): [True: 0, False: 16.9k]
  ------------------
  326|      0|		return 0;
  327|  16.9k|	for (ii=0;ii<SC_MAX_OBJECT_ID_OCTETS;ii++)
  ------------------
  |  |   46|  16.9k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (327:12): [True: 16.9k, False: 0]
  ------------------
  328|  16.9k|		if (oid->value[ii])
  ------------------
  |  Branch (328:7): [True: 16.9k, False: 0]
  ------------------
  329|  16.9k|			break;
  330|  16.9k|	if (ii==SC_MAX_OBJECT_ID_OCTETS)
  ------------------
  |  |   46|  16.9k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (330:6): [True: 0, False: 16.9k]
  ------------------
  331|      0|		return 0;
  332|  16.9k|	return 1;
  333|  16.9k|}
sc_path_set:
  355|  21.4k|{
  356|  21.4k|	if (path == NULL || id == NULL || id_len == 0 || id_len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  21.4k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (356:6): [True: 0, False: 21.4k]
  |  Branch (356:22): [True: 0, False: 21.4k]
  |  Branch (356:36): [True: 0, False: 21.4k]
  |  Branch (356:51): [True: 0, False: 21.4k]
  ------------------
  357|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  358|       |
  359|  21.4k|	memset(path, 0, sizeof(*path));
  360|  21.4k|	memcpy(path->value, id, id_len);
  361|  21.4k|	path->len   = id_len;
  362|  21.4k|	path->type  = type;
  363|  21.4k|	path->index = idx;
  364|  21.4k|	path->count = count;
  365|       |
  366|  21.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  21.4k|#define SC_SUCCESS				0
  ------------------
  367|  21.4k|}
sc_format_path:
  370|   131k|{
  371|   131k|	int type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|   131k|#define SC_PATH_TYPE_PATH		2
  ------------------
  372|       |
  373|   131k|	if (path) {
  ------------------
  |  Branch (373:6): [True: 131k, False: 0]
  ------------------
  374|   131k|		memset(path, 0, sizeof(*path));
  375|   131k|		if (*str == 'i' || *str == 'I') {
  ------------------
  |  Branch (375:7): [True: 49, False: 131k]
  |  Branch (375:22): [True: 0, False: 131k]
  ------------------
  376|     49|			type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     49|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  377|     49|			str++;
  378|     49|		}
  379|   131k|		path->len = sizeof(path->value);
  380|   131k|		if (sc_hex_to_bin(str, path->value, &path->len) >= 0) {
  ------------------
  |  Branch (380:7): [True: 131k, False: 0]
  ------------------
  381|   131k|			path->type = type;
  382|   131k|		}
  383|   131k|		path->count = -1;
  384|   131k|	}
  385|   131k|}
sc_append_path_id:
  393|  40.4k|{
  394|  40.4k|	if (dest->len + idlen > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  40.4k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (394:6): [True: 0, False: 40.4k]
  ------------------
  395|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  396|  40.4k|	memcpy(dest->value + dest->len, id, idlen);
  397|  40.4k|	dest->len += idlen;
  398|  40.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  40.4k|#define SC_SUCCESS				0
  ------------------
  399|  40.4k|}
sc_append_file_id:
  402|  40.4k|{
  403|  40.4k|	u8 id[2] = { fid >> 8, fid & 0xff };
  404|       |
  405|  40.4k|	return sc_append_path_id(dest, id, 2);
  406|  40.4k|}
sc_concatenate_path:
  409|  15.0k|{
  410|  15.0k|	sc_path_t tpath;
  411|       |
  412|  15.0k|	if (d == NULL || p1 == NULL || p2 == NULL)
  ------------------
  |  Branch (412:6): [True: 0, False: 15.0k]
  |  Branch (412:19): [True: 0, False: 15.0k]
  |  Branch (412:33): [True: 0, False: 15.0k]
  ------------------
  413|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  414|       |
  415|  15.0k|	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  30.1k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  15.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (415:6): [True: 0, False: 15.0k]
  |  Branch (415:42): [True: 0, False: 15.0k]
  ------------------
  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|  15.0k|	if (p1->len + p2->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  15.0k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (419:6): [True: 3, False: 15.0k]
  ------------------
  420|      3|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      3|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  421|       |
  422|  15.0k|	memset(&tpath, 0, sizeof(sc_path_t));
  423|  15.0k|	memcpy(tpath.value, p1->value, p1->len);
  424|  15.0k|	memcpy(tpath.value + p1->len, p2->value, p2->len);
  425|  15.0k|	tpath.len  = p1->len + p2->len;
  426|  15.0k|	tpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  15.0k|#define SC_PATH_TYPE_PATH		2
  ------------------
  427|       |	/* use 'index' and 'count' entry of the second path object */
  428|  15.0k|	tpath.index = p2->index;
  429|  15.0k|	tpath.count = p2->count;
  430|       |	/* the result is currently always as path */
  431|  15.0k|	tpath.type  = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  15.0k|#define SC_PATH_TYPE_PATH		2
  ------------------
  432|       |
  433|  15.0k|	*d = tpath;
  434|       |
  435|  15.0k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.0k|#define SC_SUCCESS				0
  ------------------
  436|  15.0k|}
sc_print_path:
  439|   197k|{
  440|   197k|	static char buffer[SC_MAX_PATH_STRING_SIZE + SC_MAX_AID_STRING_SIZE];
  441|       |
  442|   197k|	if (sc_path_print(buffer, sizeof(buffer), path) != SC_SUCCESS)
  ------------------
  |  |   28|   197k|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:6): [True: 0, False: 197k]
  ------------------
  443|      0|		buffer[0] = '\0';
  444|       |
  445|   197k|	return buffer;
  446|   197k|}
sc_path_print:
  449|   277k|{
  450|   277k|	size_t i;
  451|       |
  452|   277k|	if (buf == NULL || path == NULL)
  ------------------
  |  Branch (452:6): [True: 0, False: 277k]
  |  Branch (452:21): [True: 0, False: 277k]
  ------------------
  453|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  454|       |
  455|   277k|	if (buflen < path->len * 2 + path->aid.len * 2 + 3)
  ------------------
  |  Branch (455:6): [True: 354, False: 276k]
  ------------------
  456|    354|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|    354|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  457|       |
  458|   276k|	buf[0] = '\0';
  459|   276k|	if (path->aid.len)   {
  ------------------
  |  Branch (459:6): [True: 123k, False: 153k]
  ------------------
  460|   989k|		for (i = 0; i < path->aid.len; i++)
  ------------------
  |  Branch (460:15): [True: 866k, False: 123k]
  ------------------
  461|   866k|			snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->aid.value[i]);
  462|   123k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  463|   123k|	}
  464|       |
  465|  1.04M|	for (i = 0; i < path->len; i++)
  ------------------
  |  Branch (465:14): [True: 767k, False: 276k]
  ------------------
  466|   767k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->value[i]);
  467|   276k|	if (!path->aid.len && path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|   153k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (467:6): [True: 153k, False: 123k]
  |  Branch (467:24): [True: 27.9k, False: 125k]
  ------------------
  468|  27.9k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  469|       |
  470|   276k|	return SC_SUCCESS;
  ------------------
  |  |   28|   276k|#define SC_SUCCESS				0
  ------------------
  471|   277k|}
sc_compare_path:
  474|  16.1k|{
  475|  16.1k|	return path1->len == path2->len
  ------------------
  |  Branch (475:9): [True: 14.1k, False: 2.01k]
  ------------------
  476|  14.1k|		&& !memcmp(path1->value, path2->value, path1->len);
  ------------------
  |  Branch (476:6): [True: 141, False: 13.9k]
  ------------------
  477|  16.1k|}
sc_compare_path_prefix:
  480|  11.8k|{
  481|  11.8k|	sc_path_t tpath;
  482|       |
  483|  11.8k|	if (prefix->len > path->len)
  ------------------
  |  Branch (483:6): [True: 20, False: 11.7k]
  ------------------
  484|     20|		return 0;
  485|       |
  486|  11.7k|	tpath     = *path;
  487|  11.7k|	tpath.len = prefix->len;
  488|       |
  489|  11.7k|	return sc_compare_path(&tpath, prefix);
  490|  11.8k|}
sc_get_mf_path:
  493|  15.4k|{
  494|  15.4k|	static const sc_path_t mf_path = {
  495|  15.4k|		{0x3f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2,
  496|  15.4k|		0,
  497|  15.4k|		0,
  498|  15.4k|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|  15.4k|#define SC_PATH_TYPE_PATH		2
  ------------------
  499|  15.4k|		{{0},0}
  500|  15.4k|	};
  501|  15.4k|	return &mf_path;
  502|  15.4k|}
sc_file_add_acl_entry:
  506|   171k|{
  507|   171k|	sc_acl_entry_t *p, *_new;
  508|       |
  509|   171k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   171k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (509:6): [True: 0, False: 171k]
  |  Branch (509:22): [True: 0, False: 171k]
  ------------------
  510|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  511|      0|	}
  512|       |
  513|   171k|	switch (method) {
  514|  41.5k|	case SC_AC_NEVER:
  ------------------
  |  |  163|  41.5k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  |  Branch (514:2): [True: 41.5k, False: 129k]
  ------------------
  515|  41.5k|		sc_file_clear_acl_entries(file, operation);
  516|  41.5k|		file->acl[operation] = (sc_acl_entry_t *) 1;
  517|  41.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  41.5k|#define SC_SUCCESS				0
  ------------------
  518|  6.35k|	case SC_AC_NONE:
  ------------------
  |  |  150|  6.35k|#define SC_AC_NONE			0x00000000
  ------------------
  |  Branch (518:2): [True: 6.35k, False: 165k]
  ------------------
  519|  6.35k|		sc_file_clear_acl_entries(file, operation);
  520|  6.35k|		file->acl[operation] = (sc_acl_entry_t *) 2;
  521|  6.35k|		return SC_SUCCESS;
  ------------------
  |  |   28|  6.35k|#define SC_SUCCESS				0
  ------------------
  522|  2.65k|	case SC_AC_UNKNOWN:
  ------------------
  |  |  162|  2.65k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  |  Branch (522:2): [True: 2.65k, False: 168k]
  ------------------
  523|  2.65k|		sc_file_clear_acl_entries(file, operation);
  524|  2.65k|		file->acl[operation] = (sc_acl_entry_t *) 3;
  525|  2.65k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.65k|#define SC_SUCCESS				0
  ------------------
  526|   120k|	default:
  ------------------
  |  Branch (526:2): [True: 120k, False: 50.5k]
  ------------------
  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|   120k|		if (file->acl[operation] == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (530:7): [True: 12, False: 120k]
  ------------------
  531|     12|			return SC_SUCCESS;
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
  532|   120k|		if (file->acl[operation] == (sc_acl_entry_t *) 2
  ------------------
  |  Branch (532:7): [True: 1.16k, False: 119k]
  ------------------
  533|   119k|		 || file->acl[operation] == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (533:7): [True: 15, False: 119k]
  ------------------
  534|  1.18k|			file->acl[operation] = NULL;
  535|   171k|	}
  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|   160k|	for (p = file->acl[operation]; p != NULL; p = p->next) {
  ------------------
  |  Branch (539:33): [True: 42.7k, False: 117k]
  ------------------
  540|  42.7k|		if ((p->method == method) && (p->key_ref == key_ref))
  ------------------
  |  Branch (540:7): [True: 39.9k, False: 2.81k]
  |  Branch (540:32): [True: 3.06k, False: 36.9k]
  ------------------
  541|  3.06k|			return SC_SUCCESS;
  ------------------
  |  |   28|  3.06k|#define SC_SUCCESS				0
  ------------------
  542|  42.7k|	}
  543|       |
  544|   117k|	_new = malloc(sizeof(sc_acl_entry_t));
  545|   117k|	if (_new == NULL)
  ------------------
  |  Branch (545:6): [True: 0, False: 117k]
  ------------------
  546|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  547|   117k|	_new->method = method;
  548|   117k|	_new->key_ref = (unsigned)key_ref;
  549|   117k|	_new->next = NULL;
  550|       |
  551|   117k|	p = file->acl[operation];
  552|   117k|	if (p == NULL) {
  ------------------
  |  Branch (552:6): [True: 110k, False: 7.61k]
  ------------------
  553|   110k|		file->acl[operation] = _new;
  554|   110k|		return SC_SUCCESS;
  ------------------
  |  |   28|   110k|#define SC_SUCCESS				0
  ------------------
  555|   110k|	}
  556|  37.6k|	while (p->next != NULL)
  ------------------
  |  Branch (556:9): [True: 30.0k, False: 7.61k]
  ------------------
  557|  30.0k|		p = p->next;
  558|  7.61k|	p->next = _new;
  559|       |
  560|  7.61k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.61k|#define SC_SUCCESS				0
  ------------------
  561|   117k|}
sc_file_get_acl_entry:
  565|   313k|{
  566|   313k|	sc_acl_entry_t *p;
  567|   313k|	static const sc_acl_entry_t e_never = {
  568|   313k|		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  163|   313k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   313k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  569|   313k|	};
  570|   313k|	static const sc_acl_entry_t e_none = {
  571|   313k|		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  150|   313k|#define SC_AC_NONE			0x00000000
  ------------------
              		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   313k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  572|   313k|	};
  573|   313k|	static const sc_acl_entry_t e_unknown = {
  574|   313k|		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  162|   313k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   313k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  575|   313k|	};
  576|       |
  577|   313k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   313k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (577:6): [True: 0, False: 313k]
  |  Branch (577:22): [True: 0, False: 313k]
  ------------------
  578|      0|		return NULL;
  579|      0|	}
  580|       |
  581|   313k|	p = file->acl[operation];
  582|   313k|	if (p == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (582:6): [True: 1.64k, False: 312k]
  ------------------
  583|  1.64k|		return &e_never;
  584|   312k|	if (p == (sc_acl_entry_t *) 2)
  ------------------
  |  Branch (584:6): [True: 756, False: 311k]
  ------------------
  585|    756|		return &e_none;
  586|   311k|	if (p == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (586:6): [True: 955, False: 310k]
  ------------------
  587|    955|		return &e_unknown;
  588|       |
  589|   310k|	return file->acl[operation];
  590|   311k|}
sc_file_clear_acl_entries:
  593|  2.78M|{
  594|  2.78M|	sc_acl_entry_t *e;
  595|       |
  596|  2.78M|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  2.78M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (596:6): [True: 0, False: 2.78M]
  |  Branch (596:22): [True: 0, False: 2.78M]
  ------------------
  597|      0|		return;
  598|      0|	}
  599|       |
  600|  2.78M|	e = file->acl[operation];
  601|  2.78M|	if (e == (sc_acl_entry_t *) 1 ||
  ------------------
  |  Branch (601:6): [True: 41.5k, False: 2.74M]
  ------------------
  602|  2.74M|	    e == (sc_acl_entry_t *) 2 ||
  ------------------
  |  Branch (602:6): [True: 5.19k, False: 2.73M]
  ------------------
  603|  2.73M|	    e == (sc_acl_entry_t *) 3) {
  ------------------
  |  Branch (603:6): [True: 2.64k, False: 2.73M]
  ------------------
  604|  49.3k|		file->acl[operation] = NULL;
  605|  49.3k|		return;
  606|  49.3k|	}
  607|       |
  608|  2.85M|	while (e != NULL) {
  ------------------
  |  Branch (608:9): [True: 117k, False: 2.73M]
  ------------------
  609|   117k|		sc_acl_entry_t *tmp = e->next;
  610|   117k|		free(e);
  611|   117k|		e = tmp;
  612|   117k|	}
  613|       |	file->acl[operation] = NULL;
  614|  2.73M|}
sc_file_new:
  617|  88.2k|{
  618|  88.2k|	sc_file_t *file = (sc_file_t *)calloc(1, sizeof(sc_file_t));
  619|  88.2k|	if (file == NULL)
  ------------------
  |  Branch (619:6): [True: 0, False: 88.2k]
  ------------------
  620|      0|		return NULL;
  621|       |
  622|  88.2k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  88.2k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  623|  88.2k|	return file;
  624|  88.2k|}
sc_file_free:
  627|   237k|{
  628|   237k|	unsigned int i;
  629|   237k|	if (file == NULL || !sc_file_valid(file))
  ------------------
  |  Branch (629:6): [True: 149k, False: 88.2k]
  |  Branch (629:22): [True: 0, False: 88.2k]
  ------------------
  630|   149k|		return;
  631|  88.2k|	file->magic = 0;
  632|  2.82M|	for (i = 0; i < SC_MAX_AC_OPS; i++)
  ------------------
  |  |  198|  2.82M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (632:14): [True: 2.73M, False: 88.2k]
  ------------------
  633|  2.73M|		sc_file_clear_acl_entries(file, i);
  634|  88.2k|	if (file->sec_attr)
  ------------------
  |  Branch (634:6): [True: 928, False: 87.3k]
  ------------------
  635|    928|		free(file->sec_attr);
  636|  88.2k|	if (file->prop_attr)
  ------------------
  |  Branch (636:6): [True: 689, False: 87.5k]
  ------------------
  637|    689|		free(file->prop_attr);
  638|  88.2k|	if (file->type_attr)
  ------------------
  |  Branch (638:6): [True: 2.67k, False: 85.5k]
  ------------------
  639|  2.67k|		free(file->type_attr);
  640|  88.2k|	if (file->encoded_content)
  ------------------
  |  Branch (640:6): [True: 0, False: 88.2k]
  ------------------
  641|      0|		free(file->encoded_content);
  642|  88.2k|	free(file);
  643|  88.2k|}
sc_file_dup:
  646|  10.1k|{
  647|  10.1k|	sc_file_t *newf;
  648|  10.1k|	const sc_acl_entry_t *e;
  649|  10.1k|	unsigned int op;
  650|       |
  651|  10.1k|	if (!dest)
  ------------------
  |  Branch (651:6): [True: 0, False: 10.1k]
  ------------------
  652|      0|		return;
  653|  10.1k|	*dest = NULL;
  654|  10.1k|	if (!sc_file_valid(src))
  ------------------
  |  Branch (654:6): [True: 0, False: 10.1k]
  ------------------
  655|      0|		return;
  656|  10.1k|	newf = sc_file_new();
  657|  10.1k|	if (newf == NULL)
  ------------------
  |  Branch (657:6): [True: 0, False: 10.1k]
  ------------------
  658|      0|		return;
  659|  10.1k|	*dest = newf;
  660|       |
  661|  10.1k|	memcpy(&newf->path, &src->path, sizeof(struct sc_path));
  662|  10.1k|	memcpy(&newf->name, &src->name, sizeof(src->name));
  663|  10.1k|	newf->namelen = src->namelen;
  664|  10.1k|	newf->type    = src->type;
  665|  10.1k|	newf->shareable    = src->shareable;
  666|  10.1k|	newf->ef_structure = src->ef_structure;
  667|  10.1k|	newf->size    = src->size;
  668|  10.1k|	newf->id      = src->id;
  669|  10.1k|	newf->status  = src->status;
  670|   323k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|   323k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (670:15): [True: 313k, False: 10.1k]
  ------------------
  671|   313k|		newf->acl[op] = NULL;
  672|   313k|		e = sc_file_get_acl_entry(src, op);
  673|   313k|		if (e != NULL) {
  ------------------
  |  Branch (673:7): [True: 9.73k, False: 303k]
  ------------------
  674|  9.73k|			if (sc_file_add_acl_entry(newf, op, e->method, e->key_ref) < 0)
  ------------------
  |  Branch (674:8): [True: 0, False: 9.73k]
  ------------------
  675|      0|				goto err;
  676|  9.73k|		}
  677|   313k|	}
  678|  10.1k|	newf->record_length = src->record_length;
  679|  10.1k|	newf->record_count  = src->record_count;
  680|       |
  681|  10.1k|	if (sc_file_set_sec_attr(newf, src->sec_attr, src->sec_attr_len) < 0)
  ------------------
  |  Branch (681:6): [True: 0, False: 10.1k]
  ------------------
  682|      0|		goto err;
  683|  10.1k|	if (sc_file_set_prop_attr(newf, src->prop_attr, src->prop_attr_len) < 0)
  ------------------
  |  Branch (683:6): [True: 0, False: 10.1k]
  ------------------
  684|      0|		goto err;
  685|  10.1k|	if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
  ------------------
  |  Branch (685:6): [True: 0, False: 10.1k]
  ------------------
  686|      0|		goto err;
  687|  10.1k|	if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
  ------------------
  |  Branch (687:6): [True: 0, False: 10.1k]
  ------------------
  688|      0|		goto err;
  689|  10.1k|	return;
  690|  10.1k|err:
  691|      0|	sc_file_free(newf);
  692|       |	*dest = NULL;
  693|      0|}
sc_file_set_sec_attr:
  697|  11.2k|{
  698|  11.2k|	u8 *tmp;
  699|  11.2k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (699:6): [True: 0, False: 11.2k]
  ------------------
  700|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  701|      0|	}
  702|       |
  703|  11.2k|	if (sec_attr == NULL || sec_attr_len == 0) {
  ------------------
  |  Branch (703:6): [True: 10.1k, False: 1.13k]
  |  Branch (703:26): [True: 106, False: 1.02k]
  ------------------
  704|  10.2k|		if (file->sec_attr != NULL)
  ------------------
  |  Branch (704:7): [True: 72, False: 10.1k]
  ------------------
  705|     72|			free(file->sec_attr);
  706|  10.2k|		file->sec_attr = NULL;
  707|  10.2k|		file->sec_attr_len = 0;
  708|  10.2k|		return 0;
  709|  10.2k|	 }
  710|  1.02k|	tmp = (u8 *) realloc(file->sec_attr, sec_attr_len);
  711|  1.02k|	if (!tmp) {
  ------------------
  |  Branch (711:6): [True: 0, False: 1.02k]
  ------------------
  712|      0|		if (file->sec_attr)
  ------------------
  |  Branch (712:7): [True: 0, False: 0]
  ------------------
  713|      0|			free(file->sec_attr);
  714|      0|		file->sec_attr     = NULL;
  715|      0|		file->sec_attr_len = 0;
  716|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  717|      0|	}
  718|  1.02k|	file->sec_attr = tmp;
  719|  1.02k|	memcpy(file->sec_attr, sec_attr, sec_attr_len);
  720|  1.02k|	file->sec_attr_len = sec_attr_len;
  721|       |
  722|  1.02k|	return 0;
  723|  1.02k|}
sc_file_set_prop_attr:
  727|  11.2k|{
  728|  11.2k|	u8 *tmp;
  729|  11.2k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (729:6): [True: 0, False: 11.2k]
  ------------------
  730|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  731|      0|	}
  732|       |
  733|  11.2k|	if (prop_attr == NULL || prop_attr_len == 0) {
  ------------------
  |  Branch (733:6): [True: 10.0k, False: 1.17k]
  |  Branch (733:27): [True: 345, False: 827]
  ------------------
  734|  10.4k|		if (file->prop_attr != NULL)
  ------------------
  |  Branch (734:7): [True: 67, False: 10.3k]
  ------------------
  735|     67|			free(file->prop_attr);
  736|  10.4k|		file->prop_attr = NULL;
  737|  10.4k|		file->prop_attr_len = 0;
  738|  10.4k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.4k|#define SC_SUCCESS				0
  ------------------
  739|  10.4k|	 }
  740|    827|	tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
  741|    827|	if (!tmp) {
  ------------------
  |  Branch (741:6): [True: 0, False: 827]
  ------------------
  742|      0|		if (file->prop_attr)
  ------------------
  |  Branch (742:7): [True: 0, False: 0]
  ------------------
  743|      0|			free(file->prop_attr);
  744|      0|		file->prop_attr = NULL;
  745|      0|		file->prop_attr_len = 0;
  746|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  747|      0|	}
  748|    827|	file->prop_attr = tmp;
  749|    827|	memcpy(file->prop_attr, prop_attr, prop_attr_len);
  750|    827|	file->prop_attr_len = prop_attr_len;
  751|       |
  752|    827|	return SC_SUCCESS;
  ------------------
  |  |   28|    827|#define SC_SUCCESS				0
  ------------------
  753|    827|}
sc_file_set_type_attr:
  757|  12.6k|{
  758|  12.6k|	u8 *tmp;
  759|  12.6k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (759:6): [True: 0, False: 12.6k]
  ------------------
  760|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  761|      0|	}
  762|       |
  763|  12.6k|	if (type_attr == NULL || type_attr_len == 0) {
  ------------------
  |  Branch (763:6): [True: 9.52k, False: 3.15k]
  |  Branch (763:27): [True: 0, False: 3.15k]
  ------------------
  764|  9.52k|		if (file->type_attr != NULL)
  ------------------
  |  Branch (764:7): [True: 0, False: 9.52k]
  ------------------
  765|      0|			free(file->type_attr);
  766|  9.52k|		file->type_attr = NULL;
  767|  9.52k|		file->type_attr_len = 0;
  768|  9.52k|		return SC_SUCCESS;
  ------------------
  |  |   28|  9.52k|#define SC_SUCCESS				0
  ------------------
  769|  9.52k|	 }
  770|  3.15k|	tmp = (u8 *) realloc(file->type_attr, type_attr_len);
  771|  3.15k|	if (!tmp) {
  ------------------
  |  Branch (771:6): [True: 0, False: 3.15k]
  ------------------
  772|      0|		if (file->type_attr)
  ------------------
  |  Branch (772:7): [True: 0, False: 0]
  ------------------
  773|      0|			free(file->type_attr);
  774|      0|		file->type_attr = NULL;
  775|      0|		file->type_attr_len = 0;
  776|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  777|      0|	}
  778|  3.15k|	file->type_attr = tmp;
  779|  3.15k|	memcpy(file->type_attr, type_attr, type_attr_len);
  780|  3.15k|	file->type_attr_len = type_attr_len;
  781|       |
  782|  3.15k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.15k|#define SC_SUCCESS				0
  ------------------
  783|  3.15k|}
sc_file_set_content:
  788|  10.1k|{
  789|  10.1k|	u8 *tmp;
  790|  10.1k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (790:6): [True: 0, False: 10.1k]
  ------------------
  791|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  792|      0|	}
  793|       |
  794|  10.1k|	if (content == NULL || content_len == 0) {
  ------------------
  |  Branch (794:6): [True: 10.1k, False: 0]
  |  Branch (794:25): [True: 0, False: 0]
  ------------------
  795|  10.1k|		if (file->encoded_content != NULL)
  ------------------
  |  Branch (795:7): [True: 0, False: 10.1k]
  ------------------
  796|      0|			free(file->encoded_content);
  797|  10.1k|		file->encoded_content = NULL;
  798|  10.1k|		file->encoded_content_len = 0;
  799|  10.1k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.1k|#define SC_SUCCESS				0
  ------------------
  800|  10.1k|	}
  801|       |
  802|      0|	tmp = (u8 *) realloc(file->encoded_content, content_len);
  803|      0|	if (!tmp) {
  ------------------
  |  Branch (803:6): [True: 0, False: 0]
  ------------------
  804|      0|		if (file->encoded_content)
  ------------------
  |  Branch (804:7): [True: 0, False: 0]
  ------------------
  805|      0|			free(file->encoded_content);
  806|      0|		file->encoded_content = NULL;
  807|      0|		file->encoded_content_len = 0;
  808|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  809|      0|	}
  810|       |
  811|      0|	file->encoded_content = tmp;
  812|      0|	memcpy(file->encoded_content, content, content_len);
  813|      0|	file->encoded_content_len = content_len;
  814|       |
  815|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  816|      0|}
sc_file_valid:
  819|   143k|int sc_file_valid(const sc_file_t *file) {
  820|   143k|	if (file == NULL)
  ------------------
  |  Branch (820:6): [True: 0, False: 143k]
  ------------------
  821|      0|		return 0;
  822|   143k|	return file->magic == SC_FILE_MAGIC;
  ------------------
  |  |   57|   143k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  823|   143k|}
_sc_parse_atr:
  826|  14.1k|{
  827|  14.1k|	u8 *p = reader->atr.value;
  828|  14.1k|	int atr_len = (int) reader->atr.len;
  829|  14.1k|	int n_hist, x;
  830|  14.1k|	int tx[4] = {-1, -1, -1, -1};
  831|  14.1k|	int i, FI, DI;
  832|  14.1k|	const int Fi_table[] = {
  833|  14.1k|		372, 372, 558, 744, 1116, 1488, 1860, -1,
  834|  14.1k|		-1, 512, 768, 1024, 1536, 2048, -1, -1 };
  835|  14.1k|	const int f_table[] = {
  836|  14.1k|		40, 50, 60, 80, 120, 160, 200, -1,
  837|  14.1k|		-1, 50, 75, 100, 150, 200, -1, -1 };
  838|  14.1k|	const int Di_table[] = {
  839|  14.1k|		-1, 1, 2, 4, 8, 16, 32, -1,
  840|  14.1k|		12, 20, -1, -1, -1, -1, -1, -1 };
  841|       |
  842|  14.1k|	reader->atr_info.hist_bytes_len = 0;
  843|  14.1k|	reader->atr_info.hist_bytes = NULL;
  844|       |
  845|  14.1k|	if (atr_len == 0) {
  ------------------
  |  Branch (845:6): [True: 4.38k, False: 9.77k]
  ------------------
  846|  4.38k|		sc_log(reader->ctx, "empty ATR - card not present?\n");
  ------------------
  |  |   71|  4.38k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  847|  4.38k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  4.38k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  848|  4.38k|	}
  849|       |
  850|  9.77k|	if (p[0] != 0x3B && p[0] != 0x3F) {
  ------------------
  |  Branch (850:6): [True: 670, False: 9.10k]
  |  Branch (850:22): [True: 643, False: 27]
  ------------------
  851|    643|		sc_log(reader->ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
  ------------------
  |  |   71|    643|#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|    643|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    643|#define SC_ERROR_INTERNAL			-1400
  ------------------
  853|    643|	}
  854|  9.12k|	n_hist = p[1] & 0x0F;
  855|  9.12k|	x = p[1] >> 4;
  856|  9.12k|	p += 2;
  857|  9.12k|	atr_len -= 2;
  858|  45.0k|	for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (858:14): [True: 36.0k, False: 8.97k]
  |  Branch (858:23): [True: 35.9k, False: 150]
  ------------------
  859|  35.9k|                if (x & (1 << i)) {
  ------------------
  |  Branch (859:21): [True: 24.3k, False: 11.5k]
  ------------------
  860|  24.3k|                        tx[i] = *p;
  861|  24.3k|                        p++;
  862|  24.3k|                        atr_len--;
  863|  24.3k|                } else
  864|  11.5k|                        tx[i] = -1;
  865|  35.9k|        }
  866|  9.12k|	if (tx[0] >= 0) {
  ------------------
  |  Branch (866:6): [True: 8.13k, False: 996]
  ------------------
  867|  8.13k|		reader->atr_info.FI = FI = tx[0] >> 4;
  868|  8.13k|		reader->atr_info.DI = DI = tx[0] & 0x0F;
  869|  8.13k|		reader->atr_info.Fi = Fi_table[FI];
  870|  8.13k|		reader->atr_info.f = f_table[FI];
  871|  8.13k|		reader->atr_info.Di = Di_table[DI];
  872|  8.13k|	} else {
  873|    996|		reader->atr_info.Fi = -1;
  874|    996|		reader->atr_info.f = -1;
  875|    996|		reader->atr_info.Di = -1;
  876|    996|	}
  877|  9.12k|	if (tx[2] >= 0)
  ------------------
  |  Branch (877:6): [True: 6.02k, False: 3.10k]
  ------------------
  878|  6.02k|		reader->atr_info.N = tx[3];
  879|  3.10k|	else
  880|  3.10k|		reader->atr_info.N = -1;
  881|  19.1k|	while (tx[3] > 0 && tx[3] & 0xF0 && atr_len > 0) {
  ------------------
  |  Branch (881:9): [True: 10.2k, False: 8.90k]
  |  Branch (881:22): [True: 10.0k, False: 196]
  |  Branch (881:38): [True: 9.98k, False: 28]
  ------------------
  882|  9.98k|		x = tx[3] >> 4;
  883|  49.8k|		for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (883:15): [True: 39.9k, False: 9.96k]
  |  Branch (883:24): [True: 39.8k, False: 24]
  ------------------
  884|  39.8k|	                if (x & (1 << i)) {
  ------------------
  |  Branch (884:22): [True: 15.2k, False: 24.6k]
  ------------------
  885|  15.2k|	                        tx[i] = *p;
  886|  15.2k|	                        p++;
  887|  15.2k|	                        atr_len--;
  888|  15.2k|	                } else
  889|  24.6k|	                        tx[i] = -1;
  890|  39.8k|		}
  891|  9.98k|	}
  892|  9.12k|	if (atr_len <= 0)
  ------------------
  |  Branch (892:6): [True: 183, False: 8.94k]
  ------------------
  893|    183|		return SC_SUCCESS;
  ------------------
  |  |   28|    183|#define SC_SUCCESS				0
  ------------------
  894|  8.94k|	if (n_hist > atr_len)
  ------------------
  |  Branch (894:6): [True: 720, False: 8.22k]
  ------------------
  895|    720|		n_hist = atr_len;
  896|  8.94k|	reader->atr_info.hist_bytes_len = n_hist;
  897|  8.94k|	reader->atr_info.hist_bytes = p;
  898|  8.94k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.94k|#define SC_SUCCESS				0
  ------------------
  899|  9.12k|}
sc_mem_secure_alloc:
  902|    609|{
  903|    609|	void *p;
  904|       |
  905|       |#ifdef _WIN32
  906|       |	p = VirtualAlloc(NULL, len, MEM_COMMIT, PAGE_READWRITE);
  907|       |	if (p != NULL) {
  908|       |		VirtualLock(p, len);
  909|       |	}
  910|       |#else
  911|    609|	p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  912|    609|	if (p != NULL) {
  ------------------
  |  Branch (912:6): [True: 609, False: 0]
  ------------------
  913|    609|		mlock(p, len);
  914|    609|	}
  915|    609|#endif
  916|       |
  917|    609|	return p;
  918|    609|}
sc_mem_secure_free:
  921|    609|{
  922|       |#ifdef _WIN32
  923|       |	VirtualUnlock(ptr, len);
  924|       |	VirtualFree(ptr, 0, MEM_RELEASE);
  925|       |#else
  926|    609|	munlock(ptr, len);
  927|    609|	munmap(ptr, len);
  928|    609|#endif
  929|    609|}
sc_mem_clear:
  932|  35.6k|{
  933|  35.6k|	if (len > 0)   {
  ------------------
  |  Branch (933:6): [True: 35.6k, False: 0]
  ------------------
  934|       |#ifdef HAVE_MEMSET_S
  935|       |		memset_s(ptr, len, 0, len);
  936|       |#elif _WIN32
  937|       |		SecureZeroMemory(ptr, len);
  938|       |#elif HAVE_EXPLICIT_BZERO
  939|       |		explicit_bzero(ptr, len);
  940|       |#elif ENABLE_OPENSSL
  941|       |		OPENSSL_cleanse(ptr, len);
  942|       |#else
  943|       |		memset(ptr, 0, len);
  944|       |#endif
  945|  35.6k|	}
  946|  35.6k|}
sc_compacttlv_find_tag:
 1060|    421|{
 1061|    421|	if (buf != NULL) {
  ------------------
  |  Branch (1061:6): [True: 421, False: 0]
  ------------------
 1062|    421|		size_t idx;
 1063|    421|		u8 plain_tag = tag & 0xF0;
 1064|    421|		size_t expected_len = tag & 0x0F;
 1065|       |
 1066|  17.0k|		for (idx = 0; idx < len; idx++) {
  ------------------
  |  Branch (1066:17): [True: 16.8k, False: 218]
  ------------------
 1067|  16.8k|			u8 ctag = buf[idx] & 0xF0;
 1068|  16.8k|			size_t ctag_len = buf[idx] & 0x0F;
 1069|  16.8k|			if (ctag == plain_tag && idx + ctag_len < len &&
  ------------------
  |  Branch (1069:8): [True: 670, False: 16.1k]
  |  Branch (1069:29): [True: 653, False: 17]
  ------------------
 1070|    653|					(expected_len == 0 || expected_len == ctag_len)) {
  ------------------
  |  Branch (1070:7): [True: 146, False: 507]
  |  Branch (1070:28): [True: 57, False: 450]
  ------------------
 1071|    203|				if (outlen != NULL)
  ------------------
  |  Branch (1071:9): [True: 146, False: 57]
  ------------------
 1072|    146|					*outlen = ctag_len;
 1073|    203|				return buf + (idx + 1);
 1074|    203|			}
 1075|  16.6k|			idx += ctag_len;
 1076|  16.6k|		}
 1077|    421|	}
 1078|    218|	return NULL;
 1079|    421|}
sc_mutex_create:
 1084|  28.3k|{
 1085|  28.3k|	if (ctx == NULL)
  ------------------
  |  Branch (1085:6): [True: 0, False: 28.3k]
  ------------------
 1086|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1087|  28.3k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->create_mutex != NULL)
  ------------------
  |  Branch (1087:6): [True: 0, False: 28.3k]
  |  Branch (1087:33): [True: 0, False: 0]
  ------------------
 1088|      0|		return ctx->thread_ctx->create_mutex(mutex);
 1089|  28.3k|	else
 1090|  28.3k|		return SC_SUCCESS;
  ------------------
  |  |   28|  28.3k|#define SC_SUCCESS				0
  ------------------
 1091|  28.3k|}
sc_mutex_lock:
 1094|   990k|{
 1095|   990k|	if (ctx == NULL)
  ------------------
  |  Branch (1095:6): [True: 0, False: 990k]
  ------------------
 1096|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1097|   990k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->lock_mutex != NULL)
  ------------------
  |  Branch (1097:6): [True: 0, False: 990k]
  |  Branch (1097:33): [True: 0, False: 0]
  ------------------
 1098|      0|		return ctx->thread_ctx->lock_mutex(mutex);
 1099|   990k|	else
 1100|   990k|		return SC_SUCCESS;
  ------------------
  |  |   28|   990k|#define SC_SUCCESS				0
  ------------------
 1101|   990k|}
sc_mutex_unlock:
 1104|   990k|{
 1105|   990k|	if (ctx == NULL)
  ------------------
  |  Branch (1105:6): [True: 0, False: 990k]
  ------------------
 1106|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1107|   990k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->unlock_mutex != NULL)
  ------------------
  |  Branch (1107:6): [True: 0, False: 990k]
  |  Branch (1107:33): [True: 0, False: 0]
  ------------------
 1108|      0|		return ctx->thread_ctx->unlock_mutex(mutex);
 1109|   990k|	else
 1110|   990k|		return SC_SUCCESS;
  ------------------
  |  |   28|   990k|#define SC_SUCCESS				0
  ------------------
 1111|   990k|}

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

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

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

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

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

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

fuzz_util_connect_card:
   46|  14.1k|{
   47|  14.1k|	opt_output = NULL; /* Do not create new outputfile */
   48|       |	return fuzz_connect_card(ctx, card, NULL, reader_data, reader_data_size);
   49|  14.1k|}
initialize_global:
   52|  14.2k|{
   53|       |	/* Global variables need to be reser between runs,
   54|       |	   fuzz target is called repetitively in one execution */
   55|  14.2k|	verbose = 0, opt_wait = 0, opt_raw = 0;
   56|  14.2k|	opt_reader = NULL;
   57|  14.2k|	opt_pincode = NULL, opt_key_id = NULL;
   58|  14.2k|	opt_input = NULL, opt_output = NULL;
   59|  14.2k|	opt_bind_to_aid = NULL;
   60|  14.2k|	opt_sig_format = NULL;
   61|  14.2k|	opt_crypt_flags = 0;
   62|  14.2k|	ctx = NULL;
   63|  14.2k|	card = NULL;
   64|  14.2k|	p15card = NULL;
   65|       |
   66|  14.2k|	optind = 0;
   67|  14.2k|	opterr = 0;
   68|  14.2k|	optopt = 0;
   69|  14.2k|}
test_operation:
   73|  4.48k|{
   74|  4.48k|	char *argv[] = {"./fuzz_pkcs15_crypt", op, "-p", pin, "-i", filename,
   75|  4.48k|					hash, "-f", format, NULL, NULL, NULL, NULL, NULL, NULL};
   76|  4.48k|	int argc = 9;
   77|       |
   78|  4.48k|	if (aid) {
  ------------------
  |  Branch (78:6): [True: 279, False: 4.20k]
  ------------------
   79|    279|		argv[argc++] = "--aid";
   80|    279|		argv[argc++] = aid;
   81|    279|	}
   82|  4.48k|	if (id) {
  ------------------
  |  Branch (82:6): [True: 33, False: 4.44k]
  ------------------
   83|     33|		argv[argc++] = "-k";
   84|     33|		argv[argc++] = id;
   85|     33|	}
   86|  4.48k|	if (pad)
  ------------------
  |  Branch (86:6): [True: 2.21k, False: 2.26k]
  ------------------
   87|  2.21k|		argv[argc++] = "--pkcs1";
   88|       |
   89|  4.48k|	reader_data = data;
   90|  4.48k|	reader_data_size = size;
   91|  4.48k|	_main(argc, argv);
   92|  4.48k|}
LLVMFuzzerTestOneInput:
   95|  14.2k|{
   96|  14.2k|	uint8_t operation = 0;
   97|  14.2k|	uint8_t hash = 0;
   98|  14.2k|	char *hash_options[] = {"--md5", "--sha-1", "--sha-224", "--sha-256", "--sha-384", "--sha-512"};
   99|  14.2k|	uint8_t pad = 0;
  100|  14.2k|	uint8_t format = 0;
  101|  14.2k|	char *formats[] = {"rs", "sequence", "openssl"};
  102|  14.2k|	uint8_t aid = 0;
  103|  14.2k|	char *opt_aid = NULL;
  104|  14.2k|	uint8_t id = 0;
  105|  14.2k|	char *opt_id = NULL;
  106|  14.2k|	char *pin = NULL;
  107|  14.2k|	char *filename = NULL;
  108|       |
  109|  14.2k|	if (size < 15)
  ------------------
  |  Branch (109:6): [True: 6, False: 14.2k]
  ------------------
  110|      6|		return 0;
  111|       |
  112|  14.2k|#ifdef FUZZING_ENABLED
  113|  14.2k|	fclose(stdout);
  114|  14.2k|#endif
  115|       |
  116|  14.2k|	initialize_global();
  117|       |
  118|  14.2k|	operation = data[0] % 3;
  119|  14.2k|	data++; size--;
  120|       |
  121|  14.2k|	if (!(pin = extract_word(&data, &size)))
  ------------------
  |  Branch (121:6): [True: 1, False: 14.2k]
  ------------------
  122|      1|		return 0;
  123|       |
  124|  14.2k|	if (operation == 0) { /* test random arguments */
  ------------------
  |  Branch (124:6): [True: 9.76k, False: 4.50k]
  ------------------
  125|  9.76k|		char **argv = NULL;
  126|  9.76k|		int argc = 0;
  127|       |
  128|       |		/* setup pin and input file otherwise fuzz target waits for input from stdin */
  129|  9.76k|		opt_pincode = pin;
  130|  9.76k|		opt_input = "invalid_filename";
  131|       |
  132|  9.76k|		if (get_fuzzed_argv("./fuzz_pkcs15_crypt", data, size, &argv, &argc, &reader_data, &reader_data_size) != 0)
  ------------------
  |  Branch (132:7): [True: 2, False: 9.76k]
  ------------------
  133|      2|			goto err;
  134|  9.76k|		_main(argc, argv);
  135|  9.76k|		free_arguments(argc, argv);
  136|  9.76k|	} else {
  137|       |		/* Set options */
  138|  4.50k|		if (size < 5)
  ------------------
  |  Branch (138:7): [True: 1, False: 4.50k]
  ------------------
  139|      1|			goto err;
  140|  4.50k|		hash = data[0] % 6; data++; size--;
  141|  4.50k|		pad = data[0] % 2; data++; size--;
  142|  4.50k|		format = data[0] % 3; data++; size--;
  143|       |
  144|  4.50k|		aid = data[0] % 2; data++; size--;
  145|  4.50k|		if (aid) {
  ------------------
  |  Branch (145:7): [True: 284, False: 4.21k]
  ------------------
  146|    284|			if (!(opt_aid = extract_word(&data, &size)))
  ------------------
  |  Branch (146:8): [True: 2, False: 282]
  ------------------
  147|      2|				goto err;
  148|    284|		}
  149|  4.50k|		if (size < 3)
  ------------------
  |  Branch (149:7): [True: 1, False: 4.50k]
  ------------------
  150|      1|			goto err;
  151|       |
  152|  4.50k|		id = data[0] % 2; data++; size--;
  153|  4.50k|		if (id) {
  ------------------
  |  Branch (153:7): [True: 42, False: 4.45k]
  ------------------
  154|     42|			if (!(opt_id = extract_word(&data, &size)))
  ------------------
  |  Branch (154:8): [True: 1, False: 41]
  ------------------
  155|      1|				goto err;
  156|     42|		}
  157|       |
  158|  4.49k|		if (create_input_file(&filename, &data, &size) != 0)
  ------------------
  |  Branch (158:7): [True: 17, False: 4.48k]
  ------------------
  159|     17|			goto err;
  160|  4.48k|		test_operation(operation == 1 ? "-c" : "-s", pin, data, size, filename, hash_options[hash], formats[format], opt_aid, opt_id, pad);
  ------------------
  |  Branch (160:18): [True: 3.17k, False: 1.30k]
  ------------------
  161|       |
  162|  4.48k|		remove_file(filename);
  163|  4.48k|	}
  164|       |
  165|  14.2k|err:
  166|  14.2k|	free(pin);
  167|  14.2k|	free(opt_aid);
  168|  14.2k|	free(opt_id);
  169|  14.2k|	return 0;
  170|  14.2k|}

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

get_word:
   26|   116k|{
   27|       |	/* Words are separated by one zero byte,
   28|       |	   return pointer to the next word if there is one */
   29|   116k|	const uint8_t *ptr = data;
   30|   116k|	if (!data || size == 0 || *data == 0)
  ------------------
  |  Branch (30:6): [True: 0, False: 116k]
  |  Branch (30:15): [True: 0, False: 116k]
  |  Branch (30:28): [True: 2, False: 116k]
  ------------------
   31|      2|		return NULL;
   32|       |	
   33|   116k|	ptr = memchr(data, 0, size - 1);
   34|   116k|	return ptr ? ++ptr : NULL;
  ------------------
  |  Branch (34:9): [True: 116k, False: 2]
  ------------------
   35|   116k|}
extract_word:
   38|  60.6k|{
   39|       |	/* Find word and return its copy (needs to be freed) */
   40|  60.6k|	char *result = NULL;
   41|  60.6k|	const uint8_t *ptr = NULL;
   42|       |
   43|  60.6k|	if (*size < 2)
  ------------------
  |  Branch (43:6): [True: 1, False: 60.6k]
  ------------------
   44|      1|		return NULL;
   45|       |
   46|  60.6k|	ptr = get_word(*data, *size);
   47|  60.6k|	if (!ptr)
  ------------------
  |  Branch (47:6): [True: 3, False: 60.6k]
  ------------------
   48|      3|		return NULL;
   49|  60.6k|	result = strdup((const char *)*data);
   50|  60.6k|	*size -=(ptr - *data);
   51|  60.6k|	*data = ptr;
   52|       |
   53|  60.6k|	return result;
   54|  60.6k|}
get_fuzzed_argv:
   58|  9.76k|{
   59|  9.76k|	const uint8_t *ptr = data, *help_ptr = data;
   60|  9.76k|	size_t ptr_size = size;
   61|  9.76k|	char **argv = NULL;
   62|  9.76k|	int argc = 1;
   63|       |
   64|       |	/* Count arguments until double zero bytes occurs*/
   65|  65.7k|	while(*ptr != 0) {
  ------------------
  |  Branch (65:8): [True: 56.0k, False: 9.76k]
  ------------------
   66|  56.0k|		ptr = get_word(help_ptr, ptr_size);
   67|  56.0k|		if (!ptr)
  ------------------
  |  Branch (67:7): [True: 1, False: 56.0k]
  ------------------
   68|      1|			return -1;
   69|  56.0k|		argc++;
   70|  56.0k|		ptr_size -= (ptr - help_ptr);
   71|  56.0k|		help_ptr = ptr;
   72|  56.0k|	}
   73|       |
   74|  9.76k|	if (argc > MAX_ARGC)
  ------------------
  |  |   23|  9.76k|#define MAX_ARGC 10000
  ------------------
  |  Branch (74:6): [True: 1, False: 9.76k]
  ------------------
   75|      1|		return -1;
   76|       |
   77|  9.76k|	argv = malloc((argc + 1) * sizeof(char*));
   78|  9.76k|	if (!argv)
  ------------------
  |  Branch (78:6): [True: 0, False: 9.76k]
  ------------------
   79|      0|		return -1;
   80|       |
   81|       |	/* Copy arguments into argv */
   82|  9.76k|	ptr = data;
   83|  9.76k|	ptr_size = size;
   84|  9.76k|	argv[0] = strdup(app_name);
   85|  55.7k|	for (int i = 1; i < argc; i++) {
  ------------------
  |  Branch (85:18): [True: 46.0k, False: 9.76k]
  ------------------
   86|  46.0k|		argv[i] = extract_word(&ptr, &ptr_size);
   87|  46.0k|	}
   88|  9.76k|	argv[argc] = NULL;
   89|       |
   90|  9.76k|	*argc_out = argc;
   91|  9.76k|	*argv_out = argv;
   92|  9.76k|	*reader_data = ptr + 1; /* there are two zero bytes at the end of argv */
   93|  9.76k|	*reader_data_size = ptr_size - 1;
   94|  9.76k|	return 0;
   95|  9.76k|}
get_buffer:
   98|  4.49k|{
   99|       |	/* Split buf into two parts according to length stored in first two bytes */
  100|  4.49k|	uint16_t len = 0;
  101|       |
  102|  4.49k|	if (!buf || !(*buf) || buf_len < sizeof(uint16_t))
  ------------------
  |  Branch (102:6): [True: 0, False: 4.49k]
  |  Branch (102:14): [True: 0, False: 4.49k]
  |  Branch (102:25): [True: 1, False: 4.49k]
  ------------------
  103|      1|		return 0;
  104|       |
  105|       |	/* Get length of the result buffer*/
  106|  4.49k|	len = *((uint16_t *) *buf) % max_size;
  107|  4.49k|	(*buf) += 2;
  108|  4.49k|	buf_len -= 2;
  109|  4.49k|	if (buf_len <= len) {
  ------------------
  |  Branch (109:6): [True: 9, False: 4.48k]
  ------------------
  110|      9|		*out = *buf;
  111|      9|		*out_len = buf_len;
  112|      9|		return 0;
  113|      9|	}
  114|       |
  115|       |	/* Set out buffer to new reader data*/
  116|  4.48k|	*out = *buf + len;
  117|  4.48k|	*out_len = buf_len - len;
  118|  4.48k|	return len;
  119|  4.49k|}
create_input_file:
  122|  4.49k|{
  123|  4.49k|	const uint8_t *ptr = *data;
  124|  4.49k|	size_t file_size = 0, backup_size = *size;
  125|  4.49k|	int fd = 0;
  126|  4.49k|	size_t r = 0;
  127|  4.49k|	char *filename = NULL;
  128|       |	
  129|       |	/* Split data into file content and rest*/
  130|  4.49k|	file_size = get_buffer(&ptr, *size, data, size, 6000);
  131|  4.49k|	if (file_size == 0)
  ------------------
  |  Branch (131:6): [True: 17, False: 4.48k]
  ------------------
  132|     17|		return 1;
  133|       |
  134|  4.48k|	filename = strdup("/tmp/input.XXXXXX");
  135|  4.48k|	fd = mkstemp(filename);
  136|  4.48k|	if (fd < 0) {
  ------------------
  |  Branch (136:6): [True: 0, False: 4.48k]
  ------------------
  137|      0|		*data = ptr - 2;
  138|      0|		*size = backup_size;
  139|      0|		free(filename);
  140|      0|		return 1;
  141|      0|	}
  142|       |
  143|  4.48k|	r = write(fd, ptr, file_size);
  144|  4.48k|	close(fd);
  145|       |
  146|  4.48k|	if (r != file_size) {
  ------------------
  |  Branch (146:6): [True: 0, False: 4.48k]
  ------------------
  147|      0|		*data = ptr - 2;
  148|      0|		*size = backup_size;
  149|      0|		remove_file(filename);
  150|      0|		return 1;
  151|      0|	}
  152|       |
  153|  4.48k|	*filename_out = filename;
  154|  4.48k|	return 0;
  155|  4.48k|}
remove_file:
  158|  4.48k|{
  159|  4.48k|	if (filename) {
  ------------------
  |  Branch (159:6): [True: 4.48k, False: 0]
  ------------------
  160|  4.48k|		unlink(filename);
  161|  4.48k|		free(filename);
  162|  4.48k|	}
  163|  4.48k|}
free_arguments:
  166|  9.76k|{
  167|  65.5k|	for (int i = 0; i < argc; i++) {
  ------------------
  |  Branch (167:18): [True: 55.7k, False: 9.76k]
  ------------------
  168|  55.7k|		free(argv[i]);
  169|  55.7k|	}
  170|  9.76k|	free(argv);
  171|  9.76k|}

_main:
  384|  14.2k|{
  385|  14.2k|	int err = 0, r, c, long_optind = 0;
  386|  14.2k|	int do_decipher = 0;
  387|  14.2k|	int do_sign = 0;
  388|  14.2k|	int do_print_version = 0;
  389|  14.2k|	int action_count = 0;
  390|  14.2k|	struct sc_pkcs15_object *key;
  391|  14.2k|	sc_context_param_t ctx_param;
  392|       |
  393|  4.80M|	while (1) {
  ------------------
  |  Branch (393:9): [True: 4.80M, Folded]
  ------------------
  394|  4.80M|		c = getopt_long(argc, argv, "sck:r:i:o:f:Rp:vw", options, &long_optind);
  395|  4.80M|		if (c == -1)
  ------------------
  |  Branch (395:7): [True: 14.2k, False: 4.79M]
  ------------------
  396|  14.2k|			break;
  397|  4.79M|		if (c == '?') {
  ------------------
  |  Branch (397:7): [True: 8, False: 4.79M]
  ------------------
  398|      8|			util_print_usage(app_name, options, option_help, NULL);
  399|      8|			return 2;
  400|      8|		}
  401|  4.79M|		switch (c) {
  ------------------
  |  Branch (401:11): [True: 4.79M, False: 0]
  ------------------
  402|      0|		case OPT_VERSION:
  ------------------
  |  Branch (402:3): [True: 0, False: 4.79M]
  ------------------
  403|      0|			do_print_version = 1;
  404|      0|			action_count++;
  405|      0|			break;
  406|  4.43k|		case 's':
  ------------------
  |  Branch (406:3): [True: 4.43k, False: 4.78M]
  ------------------
  407|  4.43k|			do_sign++;
  408|  4.43k|			action_count++;
  409|  4.43k|			break;
  410|  10.4k|		case 'c':
  ------------------
  |  Branch (410:3): [True: 10.4k, False: 4.78M]
  ------------------
  411|  10.4k|			do_decipher++;
  412|  10.4k|			action_count++;
  413|  10.4k|			break;
  414|    273|		case 'k':
  ------------------
  |  Branch (414:3): [True: 273, False: 4.79M]
  ------------------
  415|    273|			opt_key_id = optarg;
  416|    273|			action_count++;
  417|    273|			break;
  418|    289|		case 'r':
  ------------------
  |  Branch (418:3): [True: 289, False: 4.79M]
  ------------------
  419|    289|			opt_reader = optarg;
  420|    289|			break;
  421|  4.67k|		case 'i':
  ------------------
  |  Branch (421:3): [True: 4.67k, False: 4.78M]
  ------------------
  422|  4.67k|			opt_input = optarg;
  423|  4.67k|			break;
  424|    446|		case 'o':
  ------------------
  |  Branch (424:3): [True: 446, False: 4.79M]
  ------------------
  425|    446|			opt_output = optarg;
  426|    446|			break;
  427|  4.67k|		case 'f':
  ------------------
  |  Branch (427:3): [True: 4.67k, False: 4.78M]
  ------------------
  428|  4.67k|			opt_sig_format = optarg;
  429|  4.67k|			break;
  430|    207|		case 'R':
  ------------------
  |  Branch (430:3): [True: 207, False: 4.79M]
  ------------------
  431|    207|			opt_raw = 1;
  432|    207|			break;
  433|  1.68k|		case OPT_SHA1:
  ------------------
  |  Branch (433:3): [True: 1.68k, False: 4.79M]
  ------------------
  434|  1.68k|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  134|  1.68k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  435|  1.68k|			break;
  436|    859|		case OPT_SHA256:
  ------------------
  |  Branch (436:3): [True: 859, False: 4.79M]
  ------------------
  437|    859|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|    859|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  438|    859|			break;
  439|    306|		case OPT_SHA384:
  ------------------
  |  Branch (439:3): [True: 306, False: 4.79M]
  ------------------
  440|    306|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA384;
  ------------------
  |  |  139|    306|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  441|    306|			break;
  442|    382|		case OPT_SHA512:
  ------------------
  |  Branch (442:3): [True: 382, False: 4.79M]
  ------------------
  443|    382|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA512;
  ------------------
  |  |  140|    382|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  444|    382|			break;
  445|    380|		case OPT_SHA224:
  ------------------
  |  Branch (445:3): [True: 380, False: 4.79M]
  ------------------
  446|    380|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_SHA224;
  ------------------
  |  |  141|    380|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
  447|    380|			break;
  448|  1.06k|		case OPT_MD5:
  ------------------
  |  Branch (448:3): [True: 1.06k, False: 4.79M]
  ------------------
  449|  1.06k|			opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_MD5;
  ------------------
  |  |  135|  1.06k|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  450|  1.06k|			break;
  451|  2.41k|		case OPT_PKCS1:
  ------------------
  |  Branch (451:3): [True: 2.41k, False: 4.79M]
  ------------------
  452|  2.41k|			opt_crypt_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|  2.41k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|  2.41k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|  2.41k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  453|  2.41k|			break;
  454|  4.75M|		case 'v':
  ------------------
  |  Branch (454:3): [True: 4.75M, False: 38.1k]
  ------------------
  455|  4.75M|			verbose++;
  456|  4.75M|			break;
  457|  4.67k|		case 'p':
  ------------------
  |  Branch (457:3): [True: 4.67k, False: 4.78M]
  ------------------
  458|  4.67k|			opt_pincode = optarg;
  459|  4.67k|			break;
  460|    580|		case OPT_BIND_TO_AID:
  ------------------
  |  Branch (460:3): [True: 580, False: 4.79M]
  ------------------
  461|    580|			opt_bind_to_aid = optarg;
  462|    580|			break;
  463|    395|		case 'w':
  ------------------
  |  Branch (463:3): [True: 395, False: 4.79M]
  ------------------
  464|    395|			opt_wait = 1;
  465|    395|			break;
  466|  4.79M|		}
  467|  4.79M|	}
  468|  14.2k|	if (action_count == 0) {
  ------------------
  |  Branch (468:6): [True: 83, False: 14.1k]
  ------------------
  469|     83|		util_print_usage(app_name, options, option_help, NULL);
  470|     83|		return 2;
  471|     83|	}
  472|       |
  473|  14.1k|	if (do_print_version)   {
  ------------------
  |  Branch (473:6): [True: 0, False: 14.1k]
  ------------------
  474|      0|		printf("%s\n", OPENSC_SCM_REVISION);
  ------------------
  |  |  226|      0|#define OPENSC_SCM_REVISION "OpenSC-<version not available>, rev: 4fab8b5, commit-time: 2026-09-10 13:11:41 +0200"
  ------------------
  475|      0|		action_count--;
  476|      0|	}
  477|       |
  478|  14.1k|	if (!(opt_crypt_flags & SC_ALGORITHM_RSA_HASHES))
  ------------------
  |  |  142|  14.1k|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (478:6): [True: 9.67k, False: 4.48k]
  ------------------
  479|  9.67k|		opt_crypt_flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|  9.67k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  480|       |
  481|  14.1k|	memset(&ctx_param, 0, sizeof(ctx_param));
  482|  14.1k|	ctx_param.ver      = 0;
  483|  14.1k|	ctx_param.app_name = app_name;
  484|  14.1k|	ctx_param.debug    = verbose;
  485|  14.1k|	if (verbose)
  ------------------
  |  Branch (485:6): [True: 198, False: 13.9k]
  ------------------
  486|    198|		ctx_param.debug_file = stderr;
  ------------------
  |  |   33|    198|#define stderr stdout
  ------------------
  487|       |
  488|  14.1k|	r = sc_context_create(&ctx, &ctx_param);
  489|  14.1k|	if (r) {
  ------------------
  |  Branch (489:6): [True: 0, False: 14.1k]
  ------------------
  490|      0|		fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r));
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  491|      0|		return 1;
  492|      0|	}
  493|       |
  494|  14.1k|	err = util_connect_card_ex(ctx, &card, opt_reader, opt_wait, 0);
  ------------------
  |  |   37|  14.1k|#define util_connect_card_ex(ctx, card, id, do_wait, do_lock) fuzz_util_connect_card(ctx, card)
  ------------------
  495|  14.1k|	if (err)
  ------------------
  |  Branch (495:6): [True: 2.91k, False: 11.2k]
  ------------------
  496|  2.91k|		goto end;
  497|       |
  498|  11.2k|	if (verbose)
  ------------------
  |  Branch (498:6): [True: 141, False: 11.0k]
  ------------------
  499|    141|		fprintf(stderr, "Trying to find a PKCS #15 compatible card...\n");
  ------------------
  |  |   33|    141|#define stderr stdout
  ------------------
  500|  11.2k|	if (opt_bind_to_aid)   {
  ------------------
  |  Branch (500:6): [True: 378, False: 10.8k]
  ------------------
  501|    378|		struct sc_aid aid;
  502|       |
  503|    378|		aid.len = sizeof(aid.value);
  504|    378|		if (sc_hex_to_bin(opt_bind_to_aid, aid.value, &aid.len))   {
  ------------------
  |  Branch (504:7): [True: 103, False: 275]
  ------------------
  505|    103|			fprintf(stderr, "Invalid AID value: '%s'\n", opt_bind_to_aid);
  ------------------
  |  |   33|    103|#define stderr stdout
  ------------------
  506|    103|			err = 1;
  507|    103|			goto end;
  508|    103|		}
  509|       |
  510|    275|		r = sc_pkcs15_bind(card, &aid, &p15card);
  511|    275|	}
  512|  10.8k|	else   {
  513|  10.8k|		r = sc_pkcs15_bind(card, NULL, &p15card);
  514|  10.8k|	}
  515|  11.1k|	if (r) {
  ------------------
  |  Branch (515:6): [True: 6.92k, False: 4.21k]
  ------------------
  516|  6.92k|		fprintf(stderr, "PKCS #15 binding failed: %s\n", sc_strerror(r));
  ------------------
  |  |   33|  6.92k|#define stderr stdout
  ------------------
  517|  6.92k|		err = 1;
  518|  6.92k|		goto end;
  519|  6.92k|	}
  520|  4.21k|	if (verbose)
  ------------------
  |  Branch (520:6): [True: 80, False: 4.13k]
  ------------------
  521|     80|		fprintf(stderr, "Found %s!\n", p15card->tokeninfo->label);
  ------------------
  |  |   33|     80|#define stderr stdout
  ------------------
  522|       |
  523|  4.21k|	if (do_decipher) {
  ------------------
  |  Branch (523:6): [True: 2.78k, False: 1.43k]
  ------------------
  524|  2.78k|		if ((err = get_key(SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP, &key))
  ------------------
  |  |  306|  2.78k|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              		if ((err = get_key(SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP, &key))
  ------------------
  |  |  310|  2.78k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (524:7): [True: 2.41k, False: 367]
  ------------------
  525|    367|		 || (err = decipher(key)))
  ------------------
  |  Branch (525:7): [True: 318, False: 49]
  ------------------
  526|  2.73k|			goto end;
  527|     49|		action_count--;
  528|     49|	}
  529|       |
  530|  1.47k|	if (do_sign) {
  ------------------
  |  Branch (530:6): [True: 1.42k, False: 57]
  ------------------
  531|  1.42k|		if ((err = get_key(SC_PKCS15_PRKEY_USAGE_SIGN|
  ------------------
  |  |  307|  1.42k|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  |  Branch (531:7): [True: 1.18k, False: 242]
  ------------------
  532|  1.42k|				   SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  308|  1.42k|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  533|  1.42k|				   SC_PKCS15_PRKEY_USAGE_NONREPUDIATION, &key))
  ------------------
  |  |  314|  1.42k|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  534|    242|		 || (err = sign(key)))
  ------------------
  |  Branch (534:7): [True: 192, False: 50]
  ------------------
  535|  1.37k|			goto end;
  536|     50|		action_count--;
  537|     50|	}
  538|  14.1k|end:
  539|  14.1k|	if (p15card)
  ------------------
  |  Branch (539:6): [True: 4.21k, False: 9.93k]
  ------------------
  540|  4.21k|		sc_pkcs15_unbind(p15card);
  541|  14.1k|	if (card) {
  ------------------
  |  Branch (541:6): [True: 11.2k, False: 2.91k]
  ------------------
  542|  11.2k|		sc_disconnect_card(card);
  543|  11.2k|	}
  544|  14.1k|	if (ctx)
  ------------------
  |  Branch (544:6): [True: 14.1k, False: 0]
  ------------------
  545|  14.1k|		sc_release_context(ctx);
  546|  14.1k|	return err;
  547|  1.47k|}
fuzz_pkcs15_crypt.c:get_key:
  303|  4.20k|{
  304|  4.20k|	sc_pkcs15_object_t *key, *pin = NULL;
  305|  4.20k|	const char	*usage_name;
  306|  4.20k|	sc_pkcs15_id_t	id;
  307|  4.20k|	int		r;
  308|       |
  309|  4.20k|	usage_name = (usage & SC_PKCS15_PRKEY_USAGE_SIGN)? "signature" : "decryption";
  ------------------
  |  |  307|  4.20k|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  |  Branch (309:15): [True: 1.42k, False: 2.78k]
  ------------------
  310|       |
  311|  4.20k|	if (opt_key_id != NULL) {
  ------------------
  |  Branch (311:6): [True: 39, False: 4.16k]
  ------------------
  312|     39|		sc_pkcs15_hex_string_to_id(opt_key_id, &id);
  313|     39|		r = sc_pkcs15_find_prkey_by_id_usage(p15card, &id, usage, &key);
  314|     39|		if (r < 0) {
  ------------------
  |  Branch (314:7): [True: 37, False: 2]
  ------------------
  315|     37|			fprintf(stderr, "Unable to find private %s key '%s': %s\n",
  ------------------
  |  |   33|     37|#define stderr stdout
  ------------------
  316|     37|				usage_name, opt_key_id, sc_strerror(r));
  317|     37|			return 2;
  318|     37|		}
  319|  4.16k|	} else {
  320|  4.16k|		r = sc_pkcs15_find_prkey_by_id_usage(p15card, NULL, usage, &key);
  321|  4.16k|		if (r < 0) {
  ------------------
  |  Branch (321:7): [True: 3.30k, False: 864]
  ------------------
  322|  3.30k|			fprintf(stderr, "Unable to find any private %s key: %s\n",
  ------------------
  |  |   33|  3.30k|#define stderr stdout
  ------------------
  323|  3.30k|				usage_name, sc_strerror(r));
  324|  3.30k|			return 2;
  325|  3.30k|		}
  326|  4.16k|	}
  327|       |
  328|    866|	*result = key;
  329|       |
  330|    866|	if (key->auth_id.len) {
  ------------------
  |  Branch (330:6): [True: 753, False: 113]
  ------------------
  331|    753|		static sc_pkcs15_object_t *prev_pin = NULL;
  332|    753|		char	*pincode;
  333|       |
  334|    753|		r = sc_pkcs15_find_pin_by_auth_id(p15card, &key->auth_id, &pin);
  335|    753|		if (r) {
  ------------------
  |  Branch (335:7): [True: 5, False: 748]
  ------------------
  336|      5|			fprintf(stderr, "Unable to find PIN code for private key: %s\n",
  ------------------
  |  |   33|      5|#define stderr stdout
  ------------------
  337|      5|				sc_strerror(r));
  338|      5|			return 1;
  339|      5|		}
  340|       |
  341|       |		/* Pin already verified previously */
  342|    748|		if (pin == prev_pin && key->user_consent == 0)
  ------------------
  |  Branch (342:7): [True: 291, False: 457]
  |  Branch (342:26): [True: 285, False: 6]
  ------------------
  343|    285|			return 0;
  344|       |
  345|    463|		pincode = get_pin(pin);
  346|    463|		if (((pincode == NULL || *pincode == '\0')) &&
  ------------------
  |  Branch (346:9): [True: 2, False: 461]
  |  Branch (346:28): [True: 0, False: 461]
  ------------------
  347|      2|		    !(p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD)) {
  ------------------
  |  |  376|      2|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (347:7): [True: 2, False: 0]
  ------------------
  348|      2|			free(pincode);
  349|      2|			return 5;
  350|      2|		}
  351|       |
  352|       |		/*
  353|       |		 * Do what PKCS#11 would do for keys requiring CKA_ALWAYS_AUTHENTICATE
  354|       |		 * and CKU_CONTEXT_SPECIFIC login to let driver know this verify will be followed by
  355|       |		 * a crypto operation.  Card drivers can test for SC_AC_CONTEXT_SPECIFIC
  356|       |		 * to do any special handling.
  357|       |		 */
  358|    461|		if (key->user_consent && pin) {
  ------------------
  |  Branch (358:7): [True: 26, False: 435]
  |  Branch (358:28): [True: 26, False: 0]
  ------------------
  359|     26|			int auth_meth_saved;
  360|     26|			struct sc_pkcs15_auth_info *pinfo = (struct sc_pkcs15_auth_info *) pin->data;
  361|       |
  362|     26|			auth_meth_saved = pinfo->auth_method;
  363|       |
  364|     26|			pinfo->auth_method = SC_AC_CONTEXT_SPECIFIC;
  ------------------
  |  |  160|     26|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  365|     26|			r = sc_pkcs15_verify_pin(p15card, pin, (const u8 *)pincode, pincode ? strlen(pincode) : 0);
  ------------------
  |  Branch (365:64): [True: 26, False: 0]
  ------------------
  366|     26|			pinfo->auth_method = auth_meth_saved;
  367|     26|		} else
  368|    435|			r = sc_pkcs15_verify_pin(p15card, pin, (const u8 *)pincode, pincode ? strlen(pincode) : 0);
  ------------------
  |  Branch (368:64): [True: 435, False: 0]
  ------------------
  369|       |
  370|    461|		free(pincode);
  371|    461|		if (r) {
  ------------------
  |  Branch (371:7): [True: 250, False: 211]
  ------------------
  372|    250|			fprintf(stderr, "PIN code verification failed: %s\n", sc_strerror(r));
  ------------------
  |  |   33|    250|#define stderr stdout
  ------------------
  373|    250|			return 5;
  374|    250|		}
  375|    211|		if (verbose)
  ------------------
  |  Branch (375:7): [True: 8, False: 203]
  ------------------
  376|      8|			fprintf(stderr, "PIN code correct.\n");
  ------------------
  |  |   33|      8|#define stderr stdout
  ------------------
  377|    211|		prev_pin = pin;
  378|    211|	}
  379|       |
  380|    324|	return 0;
  381|    866|}
fuzz_pkcs15_crypt.c:get_pin:
  127|    463|{
  128|    463|	char buf[(sizeof obj->label) + 20];
  129|    463|	char *pincode;
  130|    463|	struct sc_pkcs15_auth_info *pinfo;
  131|       |
  132|    463|	if (!obj)
  ------------------
  |  Branch (132:6): [True: 0, False: 463]
  ------------------
  133|      0|		return NULL;
  134|       |
  135|    463|	pinfo = (struct sc_pkcs15_auth_info *) obj->data;
  136|    463|	if (pinfo->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|    463|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (136:6): [True: 0, False: 463]
  ------------------
  137|      0|		return NULL;
  138|       |
  139|    463|	if (opt_pincode != NULL) {
  ------------------
  |  Branch (139:6): [True: 463, False: 0]
  ------------------
  140|    463|		if (strcmp(opt_pincode, "-") == 0)
  ------------------
  |  Branch (140:7): [True: 2, False: 461]
  ------------------
  141|      2|			return readpin_stdin();
  142|    461|		else
  143|    461|			return strdup(opt_pincode);
  144|    463|	}
  145|       |
  146|      0|	snprintf(buf, sizeof(buf), "Enter PIN [%.*s]: ",
  147|      0|		(int) sizeof obj->label, obj->label);
  148|      0|	while (1) {
  ------------------
  |  Branch (148:9): [True: 0, Folded]
  ------------------
  149|      0|		pincode = getpass(buf);
  150|      0|		if (strlen(pincode) == 0)
  ------------------
  |  Branch (150:7): [True: 0, False: 0]
  ------------------
  151|      0|			return NULL;
  152|      0|		if (strlen(pincode) < pinfo->attrs.pin.min_length ||
  ------------------
  |  Branch (152:7): [True: 0, False: 0]
  ------------------
  153|      0|				strlen(pincode) > pinfo->attrs.pin.max_length)
  ------------------
  |  Branch (153:5): [True: 0, False: 0]
  ------------------
  154|      0|			continue;
  155|      0|		return strdup(pincode);
  156|      0|	}
  157|      0|}
fuzz_pkcs15_crypt.c:readpin_stdin:
  112|      2|{
  113|      2|	char buf[128];
  114|      2|	char *p;
  115|       |
  116|      2|	p = fgets(buf, sizeof(buf), stdin);
  117|      2|	if (p != NULL) {
  ------------------
  |  Branch (117:6): [True: 0, False: 2]
  ------------------
  118|      0|		p = strchr(buf, '\n');
  119|      0|		if (p != NULL)
  ------------------
  |  Branch (119:7): [True: 0, False: 0]
  ------------------
  120|      0|			*p = '\0';
  121|      0|		return strdup(buf);
  122|      0|	}
  123|      2|	return NULL;
  124|      2|}
fuzz_pkcs15_crypt.c:decipher:
  273|    367|{
  274|    367|	u8 buf[1024], out[1024];
  275|    367|	int r, len, flags;
  276|    367|	size_t c;
  277|       |
  278|    367|	if (opt_input == NULL) {
  ------------------
  |  Branch (278:6): [True: 0, False: 367]
  ------------------
  279|      0|		fprintf(stderr, "No input file specified. Reading from stdin\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  280|      0|	}
  281|    367|	c = read_input(buf, sizeof(buf));
  282|    367|	if (c <= 0)
  ------------------
  |  Branch (282:6): [True: 65, False: 302]
  ------------------
  283|     65|		return 2;
  284|       |
  285|    302|	len = sizeof(out);
  286|    302|	if (!((struct sc_pkcs15_prkey_info *) obj->data)->native) {
  ------------------
  |  Branch (286:6): [True: 2, False: 300]
  ------------------
  287|      2|                fprintf(stderr, "Deprecated non-native key detected! Upgrade your smart cards.\n");
  ------------------
  |  |   33|      2|#define stderr stdout
  ------------------
  288|      2|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      2|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  289|      2|	}
  290|       |
  291|    300|	flags = opt_crypt_flags & ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01;
  ------------------
  |  |  109|    300|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  292|    300|	r = sc_pkcs15_decipher(p15card, obj, flags, buf, c, out, len, NULL);
  293|    300|	if (r < 0) {
  ------------------
  |  Branch (293:6): [True: 251, False: 49]
  ------------------
  294|    251|		fprintf(stderr, "Decrypt failed: %s\n", sc_strerror(r));
  ------------------
  |  |   33|    251|#define stderr stdout
  ------------------
  295|    251|		return 1;
  296|    251|	}
  297|     49|	r = write_output(out, r);
  298|       |
  299|     49|	return r;
  300|    300|}
fuzz_pkcs15_crypt.c:read_input:
  160|    609|{
  161|    609|	FILE *inf;
  162|    609|	size_t c;
  163|       |
  164|    609|	if (opt_input==NULL) {
  ------------------
  |  Branch (164:6): [True: 0, False: 609]
  ------------------
  165|      0|		inf = stdin;
  166|    609|	} else {
  167|    609|		inf = fopen(opt_input, "rb");
  168|    609|		if (inf == NULL) {
  ------------------
  |  Branch (168:7): [True: 99, False: 510]
  ------------------
  169|     99|			fprintf(stderr, "Unable to open '%s' for reading.\n", opt_input);
  ------------------
  |  |   33|     99|#define stderr stdout
  ------------------
  170|     99|			return 0;
  171|     99|		}
  172|    609|	}
  173|    510|	c = fread(buf, 1, buflen, inf);
  174|    510|	if (inf!=stdin) {
  ------------------
  |  Branch (174:6): [True: 510, False: 0]
  ------------------
  175|    510|		fclose(inf);
  176|    510|	}
  177|    510|	if (c <= 0) {
  ------------------
  |  Branch (177:6): [True: 0, False: 510]
  ------------------
  178|      0|		perror("read");
  179|      0|		return 0;
  180|      0|	}
  181|    510|	return c;
  182|    510|}
fuzz_pkcs15_crypt.c:write_output:
  185|     99|{
  186|     99|	FILE *outf;
  187|     99|	int output_binary = (opt_output == NULL && opt_raw == 0 ? 0 : 1);
  ------------------
  |  Branch (187:23): [True: 99, False: 0]
  |  Branch (187:45): [True: 99, False: 0]
  ------------------
  188|       |
  189|     99|	if (opt_output != NULL) {
  ------------------
  |  Branch (189:6): [True: 0, False: 99]
  ------------------
  190|      0|		outf = fopen(opt_output, "wb");
  191|      0|		if (outf == NULL) {
  ------------------
  |  Branch (191:7): [True: 0, False: 0]
  ------------------
  192|      0|			fprintf(stderr, "Unable to open '%s' for writing.\n", opt_output);
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  193|      0|			return -1;
  194|      0|		}
  195|     99|	} else {
  196|     99|		outf = stdout;
  197|     99|	}
  198|       |
  199|     99|	if (output_binary == 0)
  ------------------
  |  Branch (199:6): [True: 99, False: 0]
  ------------------
  200|     99|		util_print_binary(outf, buf, len);
  201|      0|	else
  202|      0|		fwrite(buf, len, 1, outf);
  203|       |
  204|     99|	if (outf != stdout)
  ------------------
  |  Branch (204:6): [True: 0, False: 99]
  ------------------
  205|      0|		fclose(outf);
  206|     99|	return 0;
  207|     99|}
fuzz_pkcs15_crypt.c:sign:
  210|    242|{
  211|    242|	u8 buf[1024], out[1024];
  212|    242|	struct sc_pkcs15_prkey_info *key = (struct sc_pkcs15_prkey_info *) obj->data;
  213|    242|	int r, flags;
  214|    242|	size_t c, len;
  215|       |
  216|    242|	if (opt_input == NULL) {
  ------------------
  |  Branch (216:6): [True: 0, False: 242]
  ------------------
  217|      0|		fprintf(stderr, "No input file specified. Reading from stdin\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  218|      0|	}
  219|       |
  220|    242|	c = read_input(buf, sizeof(buf));
  221|    242|	if (c <= 0)
  ------------------
  |  Branch (221:6): [True: 34, False: 208]
  ------------------
  222|     34|		return 2;
  223|    208|	len = sizeof(out);
  224|    208|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA
  ------------------
  |  |  419|    416|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (224:6): [True: 175, False: 33]
  ------------------
  225|    175|			&& !(opt_crypt_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  109|    175|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (225:7): [True: 7, False: 168]
  ------------------
  226|      7|			&& (size_t)c != key->modulus_length/8) {
  ------------------
  |  Branch (226:7): [True: 6, False: 1]
  ------------------
  227|      6|		fprintf(stderr, "Input has to be exactly %lu bytes, when using no padding.\n",
  ------------------
  |  |   33|      6|#define stderr stdout
  ------------------
  228|      6|			(unsigned long) key->modulus_length/8);
  229|      6|		return 2;
  230|      6|	}
  231|    202|	if (!key->native) {
  ------------------
  |  Branch (231:6): [True: 2, False: 200]
  ------------------
  232|      2|		fprintf(stderr, "Deprecated non-native key detected! Upgrade your smart cards.\n");
  ------------------
  |  |   33|      2|#define stderr stdout
  ------------------
  233|      2|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      2|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  234|      2|	}
  235|       |
  236|    200|	flags = opt_crypt_flags & ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|    200|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  237|    200|	r = sc_pkcs15_compute_signature(p15card, obj, flags, buf, c, out, len, NULL);
  238|    200|	if (r < 0) {
  ------------------
  |  Branch (238:6): [True: 150, False: 50]
  ------------------
  239|    150|		fprintf(stderr, "Compute signature failed: %s\n", sc_strerror(r));
  ------------------
  |  |   33|    150|#define stderr stdout
  ------------------
  240|    150|		return 1;
  241|    150|	}
  242|     50|	len = r;
  243|       |
  244|     50|	if (obj->type == SC_PKCS15_TYPE_PRKEY_EC)   {
  ------------------
  |  |  421|     50|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (244:6): [True: 0, False: 50]
  ------------------
  245|      0|		if (opt_sig_format &&  (!strcmp(opt_sig_format, "openssl") || !strcmp(opt_sig_format, "sequence")))   {
  ------------------
  |  Branch (245:7): [True: 0, False: 0]
  |  Branch (245:27): [True: 0, False: 0]
  |  Branch (245:65): [True: 0, False: 0]
  ------------------
  246|      0|			unsigned char *seq;
  247|      0|			size_t seqlen;
  248|       |
  249|      0|			if (sc_asn1_sig_value_rs_to_sequence(ctx, out, len, &seq, &seqlen))   {
  ------------------
  |  Branch (249:8): [True: 0, False: 0]
  ------------------
  250|      0|				fprintf(stderr, "Failed to convert signature to ASN1 sequence format.\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  251|      0|				return 2;
  252|      0|			}
  253|       |
  254|      0|			if (seqlen > sizeof(out)) {
  ------------------
  |  Branch (254:8): [True: 0, False: 0]
  ------------------
  255|      0|				free(seq);
  256|      0|				fprintf(stderr, "Signature sequence too large\n");
  ------------------
  |  |   33|      0|#define stderr stdout
  ------------------
  257|      0|				return 2;
  258|      0|			}
  259|       |
  260|      0|			memcpy(out, seq, seqlen);
  261|      0|			len = seqlen;
  262|       |
  263|      0|			free(seq);
  264|      0|		}
  265|      0|	}
  266|       |
  267|     50|	r = write_output(out, len);
  268|       |
  269|     50|	return r;
  270|     50|}

util_print_binary:
  202|     99|{
  203|     99|	size_t i;
  204|       |
  205|  20.6k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (205:14): [True: 20.5k, False: 99]
  ------------------
  206|  20.5k|		unsigned char c = buf[i];
  207|  20.5k|		const char *format;
  208|  20.5k|		if (!isprint(c))
  ------------------
  |  Branch (208:7): [True: 17.1k, False: 3.32k]
  ------------------
  209|  17.1k|			format = "\\x%02X";
  210|  3.32k|		else
  211|  3.32k|			format = "%c";
  212|  20.5k|		fprintf(f, format, c);
  213|  20.5k|	}
  214|     99|	(void) fflush(f);
  215|     99|}
util_print_usage:
  260|     91|{
  261|     91|	int i;
  262|     91|	int header_shown = 0;
  263|       |
  264|     91|	if (args)
  ------------------
  |  Branch (264:6): [True: 0, False: 91]
  ------------------
  265|      0|		printf("Usage: %s [OPTIONS] %s\n", app_name, args);
  266|     91|	else
  267|     91|		printf("Usage: %s [OPTIONS]\n", app_name);
  268|       |
  269|  1.91k|	for (i = 0; options[i].name; i++) {
  ------------------
  |  Branch (269:14): [True: 1.82k, False: 91]
  ------------------
  270|  1.82k|		char buf[40];
  271|  1.82k|		const char *arg_str;
  272|       |
  273|       |		/* Skip "hidden" options */
  274|  1.82k|		if (option_help[i] == NULL)
  ------------------
  |  Branch (274:7): [True: 0, False: 1.82k]
  ------------------
  275|      0|			continue;
  276|       |
  277|  1.82k|		if (!header_shown++)
  ------------------
  |  Branch (277:7): [True: 91, False: 1.72k]
  ------------------
  278|     91|			printf("Options:\n");
  279|       |
  280|  1.82k|		switch (options[i].has_arg) {
  281|    637|		case 1:
  ------------------
  |  Branch (281:3): [True: 637, False: 1.18k]
  ------------------
  282|    637|			arg_str = " <arg>";
  283|    637|			break;
  284|      0|		case 2:
  ------------------
  |  Branch (284:3): [True: 0, False: 1.82k]
  ------------------
  285|      0|			arg_str = " [arg]";
  286|      0|			break;
  287|  1.18k|		default:
  ------------------
  |  Branch (287:3): [True: 1.18k, False: 637]
  ------------------
  288|  1.18k|			arg_str = "";
  289|  1.18k|			break;
  290|  1.82k|		}
  291|  1.82k|		if (isascii(options[i].val) &&
  ------------------
  |  Branch (291:7): [True: 1.00k, False: 819]
  ------------------
  292|  1.82k|		    isprint(options[i].val) && !isspace(options[i].val))
  ------------------
  |  Branch (292:7): [True: 1.00k, False: 0]
  |  Branch (292:34): [True: 1.00k, False: 0]
  ------------------
  293|  1.00k|			sprintf(buf, "-%c, --%s%s", options[i].val, options[i].name, arg_str);
  294|    819|		else
  295|    819|			sprintf(buf, "    --%s%s", options[i].name, arg_str);
  296|       |
  297|       |		/* print the line - wrap if necessary */
  298|  1.82k|		if (strlen(buf) > 28) {
  ------------------
  |  Branch (298:7): [True: 0, False: 1.82k]
  ------------------
  299|      0|			printf("  %s\n", buf);
  300|      0|			buf[0] = '\0';
  301|      0|		}
  302|  1.82k|		printf("  %-28s  %s\n", buf, option_help[i]);
  303|  1.82k|	}
  304|     91|}

sc_notify:
  526|      2|void sc_notify(const char *title, const char *text) {}
sc_notify_id:
  528|    411|		struct sc_pkcs15_card *p15card, enum ui_str id) {}

